Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <Windows.h>
- using namespace std;
- enum mathType
- {
- ADD = 0,
- SUB = 1,
- MUL = 2,
- DIV = 3
- };
- double calculate(mathType op, double num1, double num2);
- mathType getSumType();
- int main ()
- {
- mathType type;
- double num1, num2;
- cout << "x, /, + or - : ";
- type = getSumType();
- cout << "Please enter number 1: ";
- cin >> num1;
- cout << endl;
- cout << "Please enter number 2: ";
- cin >> num2;
- cout << endl;
- cout << calculate (type, num1, num2) << endl;
- system("PAUSE");
- return 0;
- }
- mathType getSumType()
- {
- char input = NULL;
- mathType type;
- while(input != 'x' && input != '/' && input != '+' && input != '-')
- {
- cin >> input;
- switch(input)
- {
- case 'x':
- type = MUL;
- break;
- case '/':
- type = DIV;
- break;
- case '+':
- type = ADD;
- break;
- case '-':
- type = SUB;
- break;
- default:
- cout << endl << "Invalid command!" << endl;
- break;
- }
- }
- return type;
- }
- double calculate (mathType op, double num1, double num2)
- {
- switch(op)
- {
- case MUL:
- return (num1*num2);
- break;
- case DIV:
- return (num1/num2);
- break;
- case ADD:
- return (num1+num2);
- break;
- case SUB:
- return (num1-num2);
- break;
- default:
- MessageBox(NULL, "Error, invalid type of primitive!", "Error!", NULL);
- return NULL;
- break;
- }
- }
Add Comment
Please, Sign In to add comment