Advertisement
okelikai

normalCalc

Sep 29th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath> // math
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     char operand; // setting var as char because + - etc are characters
  8.     double inputOne, inputTwo, output; // values for equasion
  9.    
  10.     cout << "Choose and operand, +, -, *, / : "; // user defines type of equasion
  11.     cin >> operand;
  12.    
  13.     cout << "Type your inputs, then press output.\n   First Input: "; // user inputs
  14.     cin >> inputOne;
  15.     cout << "   Second Input: ";
  16.     cin >> inputTwo;
  17.     cout << "\n";
  18.  
  19.     switch(operand) // to setup case vv
  20.     {
  21.         case '+': // if statement but takes text, uses '' because less data
  22.             output = inputOne + inputTwo; // math
  23.             cout << "   " <<  inputOne << operand << inputTwo << '=' << output; // pretty output for user
  24.             break;
  25.            
  26.         case '-':
  27.             output = inputOne - inputTwo;
  28.             cout << "   " <<  inputOne << operand << inputTwo << '=' << output;
  29.             break;
  30.            
  31.         case '*':
  32.             output = inputOne * inputTwo;
  33.             cout << "   " <<  inputOne << operand << inputTwo << '=' << output;
  34.             break;
  35.            
  36.         case '/':
  37.             if (inputTwo == 0) // checking if trying to divide by zero
  38.             {
  39.                 cout << "Sorry, you cannot divide by zero!";
  40.             }
  41.             else
  42.             {
  43.                 output = inputOne / inputTwo; // if not dividing by zero does math normall
  44.                 cout << "   " << inputOne << operand << inputTwo << '=' << output;
  45.             }
  46.             break;
  47.         ;
  48.     }
  49.     return 0; // return zero to close int main
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement