Advertisement
JustACodingStudent

Basic Calculator (School project)

Feb 26th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     char symbol;
  6.     double a, b, answer;
  7.     cout << "Enter your first number: ";
  8.     cin >> a;
  9.     cout << "Enter your second number: ";
  10.     cin >> b;
  11.     cout << "Enter the symbol of the operation you wish to perform.\n " << endl;
  12.     cout << "Symbols:\n " << endl;
  13.     cout << "Addition : +\n \nSubtraction: -\n \nMultiplication: *\n \nDivision: /" << endl;
  14.     cout << "-----------------" << endl;
  15.     cin >> symbol;
  16.  
  17.     if(symbol == '/' && b == 0){
  18.         cout << "Are you trying to implode the universe? No? Then don't divide by zero.";
  19.     }
  20.     else if(symbol == '+'){
  21.         answer = a + b;
  22.         cout << " \nThe answer is: " << answer;
  23.     }
  24.     else if(symbol == '-'){
  25.         answer = a - b;
  26.         cout << " \nThe answer is: " << answer;
  27.     }
  28.     else if(symbol == '*'){
  29.         answer = a * b;
  30.         cout << " \nThe answer is: " << answer;
  31.     }
  32.     else if(symbol == '/'){
  33.         answer = a / b;
  34.         cout << " \nThe answer is: " << answer;
  35.     }
  36.  
  37.     int x;
  38.     cin>>x;
  39.     return(0);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement