fork download
  1. #include <stdio.h>
  2. int main (void)
  3. {
  4.  
  5. float value1; /* floating point value to read */
  6. float value2; /* another floating point value to read */
  7.  
  8. char answer; /* To determine if more input is available */
  9. char myOperator; /* The operator to run against our two input values */
  10.  
  11. /* process expressions until the user types a 'n' when prompted */
  12. do
  13. {
  14. printf("\nType in your expression.\n");
  15. scanf("%f %c %f", &value1, &myOperator, &value2);
  16.  
  17. /* process our two values based on the operator specified */
  18. if ( myOperator == '+' )
  19. printf ("%.2f\n", value1 + value2);
  20. else if ( myOperator == '-' )
  21. printf ("%.2f\n", value1 - value2);
  22. else if ( myOperator == '*' )
  23. printf ("%.2f\n", value1 * value2);
  24. else if ( myOperator == '/' )
  25. printf ("%.2f\n", value1 / value2);
  26.  
  27. printf("\nWould you like to enter another expression? (y/n) ");
  28. scanf (" %c", &answer);
  29.  
  30. } while ( answer != 'n' );
  31.  
  32. printf("\nGoodbye");
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5284KB
stdin
5 + 9
y
5 * 4
y
10 / 20
y
6 - 20
n
stdout
Type in your expression.
14.00

Would you like to enter another expression? (y/n) 
Type in your expression.
20.00

Would you like to enter another expression? (y/n) 
Type in your expression.
0.50

Would you like to enter another expression? (y/n) 
Type in your expression.
-14.00

Would you like to enter another expression? (y/n) 
Goodbye