Advertisement
alek_

Calculator in C++ Template

Jul 3rd, 2020
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9.         // Introduction
  10.  
  11.     cout << "Welcome to calculator" << endl;
  12.  
  13.     cout << "" << endl; // Empty Space
  14.  
  15.     cout << "" << endl; // Empty Space
  16.  
  17.     cout << "Made by *enter_name*" << endl;
  18.  
  19.     cout << "" << endl; // Empty Space
  20.  
  21.     cout << "" << endl; // Empty Space
  22.  
  23.         // Calculator
  24.  
  25.     int num1; // Number 1 Variable
  26.        
  27.     int num2; // Number 2 Variable
  28.  
  29.     char opr; // Operation Variable
  30.  
  31.  
  32.         // Number 1
  33.  
  34.     cout << "Enter your first number : ";
  35.     cin >> num1;
  36.     cout << endl;
  37.  
  38.     cout << "" << endl; // Empty Space
  39.  
  40.         // Number 2
  41.  
  42.     cout << "Enter your second number : ";
  43.     cin >> num2;
  44.     cout << endl;
  45.  
  46.     cout << "" << endl; // Empty Space
  47.  
  48.         // Operation
  49.  
  50.     cout << "Enter your operation ( *, -, +, / ) : ";
  51.     cin >> opr;
  52.     cout << endl;
  53.  
  54.     cout << "" << endl; // Empty Space
  55.  
  56.         // Fetching answers
  57.  
  58.     cout << num1 << " " << opr << " " << num2 << " = ";
  59.     switch (opr) {
  60.     case '+':
  61.         cout << num1 + num2 << endl;
  62.         break;
  63.     case'-':
  64.         cout << num1 - num2 << endl;
  65.         break;
  66.     case'*':
  67.         cout << num1 * num2 << endl;
  68.         break;
  69.     case'/':
  70.         if (num2 != 0)
  71.             cout << num1 / num2 << endl;
  72.         else
  73.             cout << "ERROR \nCannot divide by zero" << endl;
  74.         break;
  75.     default:
  76.         cout << "Illegal operation" << endl;
  77.     }
  78.    
  79.         // Makes sure the Program doesn't end
  80.  
  81.     string Endless;
  82.  
  83.     cin >> Endless;
  84.  
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement