EX06-1D.C

 #include <stdio.h>
main()
{
     char arithOp;            /* Arithmetic operator  */
     float op1;               /* First operand        */
     float op2;               /* Second operand       */
     float answer;            /* Result of arithmetic */

/* Enter data */

     printf("\t\t Four - Function Calculator Version 1.0");
     printf("\n\n");
     printf("\t    Created By: Mr. Jake Rodriguez Pomperada, MAED-IT");
     printf("\n\n");
     printf( "\tEnter a calculation: " );
     scanf( "%f %c %f", &op1, &arithOp, &op2 );

/* Perform calculations */

     switch ( arithOp )
     {
  case '-':      /* Subtraction */
       op2 = -op2;
  case '+':      /* Addition */
       answer = op1 + op2;
       break;
          case '*':      /* Multiplication */
               answer = op1 * op2;
               break;
          case '/':      /* Division */
               answer = op1 / op2;
               break;
          default:       /* Bad operator */
               printf("Illegal operator  ");
               break;
     }

/* Display results */

     printf("\n\n");
     printf( "\tResult = %.1f\n", answer );
     printf("\n\n");
}

Project Homepage: