Created
September 15, 2020 20:06
-
-
Save jacks0n9/9bf00905b75fc6a48227c1da8a3d1a7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int calc(int first, int second, int op){ | |
int result; | |
if(op == '-'){ | |
result = first - second; | |
} else if(op == '+') { | |
result = first + second; | |
} else if(op == '*' || op == 'x'){ | |
result = first * second; | |
} else if(op == '/'){ | |
result = first / second; | |
} else { | |
cout << "Invaild operator" << endl; | |
exit(3); | |
} | |
return result; | |
} | |
int main() { | |
int num1, num2; | |
char op; | |
cout << "First number: " << endl; | |
cin >> num1; | |
cout << "Second number: " << endl; | |
cin >> num2; | |
cout << "Operator: " << endl; | |
cin >> op; | |
int done = calc(num1, num2, op); | |
cout << "Your result is " << done << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment