fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.  
  5. char op;
  6. double first, second;
  7. printf("Enter an operator (+, -, *, /): ");
  8. scanf("%c", &op);
  9. printf("Enter two operands: ");
  10. scanf("%lf %lf", &first, &second);
  11.  
  12. switch (op) {
  13. case '+':
  14. printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
  15. break;
  16. case '-':
  17. printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
  18. break;
  19. case '*':
  20. printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
  21. break;
  22. case '/':
  23. printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
  24. break;
  25. // operator doesn't match any case constant
  26. default:
  27. printf("Error! operator is not correct");
  28. }
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.02s 25868KB
stdin
+
1 2
stdout
#include <stdio.h>

int main() {

  char op;
  double first, second;
  printf("Enter an operator (+, -, *, /): ");
  scanf("%c", &op);
  printf("Enter two operands: ");
  scanf("%lf %lf", &first, &second);

  switch (op) {
    case '+':
      printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
      break;
    case '-':
      printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
      break;
    case '*':
      printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
      break;
    case '/':
      printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
      break;
    // operator doesn't match any case constant
    default:
      printf("Error! operator is not correct");
  }

  return 0;
}