Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int calculate(int x, int y, char op) {
- int result;
- switch (op) {
- case '+':
- result = x + y;
- break;
- case '-':
- result = x - y;
- break;
- case '*':
- result = x * y;
- break;
- case '/':
- result = x / y;
- break;
- case '%':
- result = x % y;
- break;
- default:
- cout << "calculate(): Unhandled case \n"; return 0;
- }
- return result;
- }
- int main() {
- cout << "Enter An Interger: ";
- int x;
- cin >> x;
- cout << "Enter Another Interger: ";
- int y;
- cin >> y;
- cout << "Enter an operator (+,-,*,/,%): ";
- char op;
- cin >> op;
- cout << calculate(x, y, op) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement