Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath> // math
- using namespace std;
- int main()
- {
- char operand; // setting var as char because + - etc are characters
- double inputOne, inputTwo, output; // values for equasion
- cout << "Choose and operand, +, -, *, / : "; // user defines type of equasion
- cin >> operand;
- cout << "Type your inputs, then press output.\n First Input: "; // user inputs
- cin >> inputOne;
- cout << " Second Input: ";
- cin >> inputTwo;
- cout << "\n";
- switch(operand) // to setup case vv
- {
- case '+': // if statement but takes text, uses '' because less data
- output = inputOne + inputTwo; // math
- cout << " " << inputOne << operand << inputTwo << '=' << output; // pretty output for user
- break;
- case '-':
- output = inputOne - inputTwo;
- cout << " " << inputOne << operand << inputTwo << '=' << output;
- break;
- case '*':
- output = inputOne * inputTwo;
- cout << " " << inputOne << operand << inputTwo << '=' << output;
- break;
- case '/':
- if (inputTwo == 0) // checking if trying to divide by zero
- {
- cout << "Sorry, you cannot divide by zero!";
- }
- else
- {
- output = inputOne / inputTwo; // if not dividing by zero does math normall
- cout << " " << inputOne << operand << inputTwo << '=' << output;
- }
- break;
- ;
- }
- return 0; // return zero to close int main
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement