fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. float result = 0.0;
  5. float userEntry = 0.0;
  6. char getOperand;
  7.  
  8. int main(){
  9.  
  10. printf("Calculator is on\n");
  11. printf("Initial value is 0.0, please issue an operation in the following format: ex. +5 -5 *5 or /5. Do not add more than one number to the total.\n");
  12. getOperand = getchar();
  13. scanf("%3f", &userEntry);
  14. printf("%f", userEntry);
  15. putchar(getOperand);
  16.  
  17. switch(getOperand){
  18.  
  19. case '+':
  20. printf("addition\n");
  21. break;
  22. case '-':
  23. printf("subtraction\n");
  24. break;
  25. case '/':
  26. printf("division\n");
  27. break;
  28. case '*':
  29. printf("multiplication\n");
  30. break;
  31. default:
  32. printf("UnknownOperatorException is thrown.\n");
  33. break;
  34.  
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 3460KB
stdin
+5
stdout
Calculator is on
Initial value is 0.0, please issue an operation in the following format: ex. +5 -5 *5 or /5. Do not add more than one number to the total.
5.000000+addition