Advertisement
Guest User

calculator c++

a guest
Feb 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. int num1, num2;
  10. char op;
  11.  
  12.  
  13. cout << "enter first number: ";
  14. cin >> num1;
  15. cout << "enter an operator: ";
  16. cin >> op;
  17. cout << "enter second number: ";
  18. cin >> num2;
  19. int result;
  20.  
  21.  if(op == '+'){
  22.      cout << num1 + num2;
  23.  }else if(op == '-'){
  24.      cout << num1 - num2;
  25.  }else if(op == '*'){
  26.      cout << num1 * num2;
  27.  }else if(op == '/' ){
  28.      if(num2 =! 0){
  29.          cout << "error" << endl;
  30.      }
  31.      cout << num1 / num2;
  32.  }else{
  33.      cout << "invalid operator" << endl;
  34.  }
  35.  
  36. cout << result << endl;
  37.  
  38. return 0;
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement