Advertisement
TermSpar

Console Calculator

Apr 18th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     cout << "#### Welcome to calc ####" << endl;
  9.    
  10.     cout << "Enter first number" << endl;
  11.    
  12.     int num1;
  13.     cin >> num1;
  14.    
  15.     string op;
  16.     cout << "Enter operator (+, -, *, /)" << endl;
  17.     cin >> op;
  18.    
  19.     int num2;
  20.     cout << "Enter second number" << endl;
  21.     cin >> num2;
  22.    
  23.     if(op == "+"){
  24.             cout << "Answer is: " << num1 + num2 << endl;
  25.         }else if (op == "-"){
  26.                 cout << "Answer is: " << num1 - num2 << endl;
  27.             }else if (op == "*"){
  28.                     cout << "Answer is: " << num1 * num2 << endl;
  29.                 }else if (op == "/"){
  30.                     cout << "Answer is: " << (num1/num2) << endl;
  31.                 }else{
  32.                         cout << "Invalid" << endl;
  33.                     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement