fork download
  1. #include<iostream>
  2.  
  3.  
  4. int main()
  5. {
  6. while (true) {
  7. char op;
  8. std::cout << "Enter equation to be performed --> ";
  9. std::cin >> op;
  10. if (op == 'N')
  11. break;
  12. std::cin.unget();
  13. int left_int, right_int, result;
  14. std::cin >> left_int >> op>> right_int;
  15. switch (op)
  16. {
  17. case '+':
  18. result = left_int + right_int;
  19. break;
  20. case '-':
  21. result = left_int - right_int;
  22. break;
  23. case '*':
  24. result = left_int * right_int;
  25. break;
  26. case '/':
  27. result = left_int / right_int;
  28. break;
  29. case '%':
  30. result = left_int % right_int;
  31. break;
  32. default:
  33. std::cout << "Unsuppoted operand: " << op;
  34. break;
  35. }
  36. std::cout << result << std::endl;
  37. }
  38. }
  39.  
Success #stdin #stdout 0s 3300KB
stdin
22 + 4
N
stdout
Enter equation to be performed --> 26
Enter equation to be performed -->