fork download
  1. # include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. char op;
  7. float num1, num2;
  8.  
  9. cout << "Enter operator: +, -, *, /: ";
  10. cin >> op;
  11.  
  12. cout << "Enter two operands: ";
  13. cin >> num1 >> num2;
  14.  
  15. switch(op) {
  16.  
  17. case '+':
  18. cout << num1 << " + " << num2 << " = " << num1 + num2;
  19. break;
  20.  
  21. case '-':
  22. cout << num1 << " - " << num2 << " = " << num1 - num2;
  23. break;
  24.  
  25. case '*':
  26. cout << num1 << " * " << num2 << " = " << num1 * num2;
  27. break;
  28.  
  29. case '/':
  30. cout << num1 << " / " << num2 << " = " << num1 / num2;
  31. break;
  32.  
  33. default:
  34. // If the operator is other than +, -, * or /, error message is shown
  35. cout << "Error! operator is not correct";
  36. break;
  37. }
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.01s 5516KB
stdin
Standard input is empty
stdout
Enter operator: +, -, *, /: Enter two operands: Error! operator is not correct