Advertisement
EconomicSerg

Better calculator

Jan 28th, 2021
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void calculator() {
  6.     int num1;
  7.     int num2;
  8.     string method;
  9.  
  10.     cout << "Enter a number: ";
  11.     cin >> num1;
  12.     cout << "Enter another number: ";
  13.     cin >> num2;
  14.     cout << "Add, subtract, multiply, or divide: ";
  15.     cin >> method;
  16.  
  17.     if (method == "+" || method == "add")
  18.     {
  19.         cout << num1 + num2;
  20.     }
  21.     else if (method == "-" || method == "subtract")
  22.     {
  23.         cout << num1 - num2;
  24.     }
  25.     else if (method == "*" || method == "multiply")
  26.     {
  27.         cout << num1 * num2;
  28.     }
  29.     else if (method == "/" || method == "divide")
  30.     {
  31.         cout << num1 / num2;
  32.     }
  33.     else
  34.  
  35.     {
  36.         cout << "Invalid form of math!";
  37.     }
  38.  
  39.     cout << "\n";
  40.     return calculator();
  41. }
  42.  
  43. int main()
  44. {
  45.     calculator();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement