fork download
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::endl;
  5. using std::cin;
  6.  
  7. int main()
  8. {
  9. int lhs , rhs , result = 0;
  10. char oper;
  11.  
  12. cout << "Please enter an equation [a][sign][b] ex: ( 10 + 2 ):" << endl;
  13. cin >> lhs >> oper >> rhs;
  14.  
  15. switch ( oper )
  16. {
  17. case '+':
  18. result = lhs + rhs;
  19. break;
  20. case '-':
  21. result = lhs - rhs;
  22. break;
  23. case '*':
  24. result = lhs * rhs;
  25. break;
  26. case '/':
  27. if( rhs == 0 )
  28. cout << "Error: Can't divide by 0" << endl;
  29. else
  30. result = lhs / rhs;
  31. break;
  32. default:
  33. cout << "Invalid operation" << endl;
  34. }
  35.  
  36. cout << lhs << ' ' << oper << ' ' << rhs << " = " << result << endl;
  37.  
  38. return ( 0 );
  39. }
Success #stdin #stdout 0s 3300KB
stdin
100 + 123
stdout
Please enter an equation [a][sign][b] ex: ( 10 + 2 ):
100 + 123 = 223