Skip to content

Instantly share code, notes, and snippets.

@jacks0n9
Created September 15, 2020 20:06
Show Gist options
  • Save jacks0n9/9bf00905b75fc6a48227c1da8a3d1a7f to your computer and use it in GitHub Desktop.
Save jacks0n9/9bf00905b75fc6a48227c1da8a3d1a7f to your computer and use it in GitHub Desktop.
#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