Calculator

Concepts:
switch statement

Text:
Realize a C program that:

Example:

3+9
RESULT: 3.000000 + 9.000000 = 12.000000

3^9
ERROR: operator '^' not recognized

Solution:

calc.c
#include <stdio.h>
 
int main() {
 
  float op1, op2, ris;
  char oper;
  int operator_is_recognized = 1;
 
  scanf("%f %c %f", &op1, &oper, &op2);
 
  switch(oper) {
  case '+':
    ris = op1 + op2;
    break;
  case '-':
    ris = op1 - op2;
    break;
  case '*':
    ris = op1 * op2;
    break;
  case '/':
    ris = op1 / op2;
    break;
  default:
    operator_is_recognized = 0;
  }
 
  if (operator_is_recognized)
    printf("RESULT: %f %c %f = %f\n", op1, oper, op2, ris);
  else
    printf("ERROR: operator '%c' not recognized\n", oper);
 
  return 0;
}