0
Pls help, t doesnt give result
#include <iostream> using namespace std; int calculate(int x, int y, char op) { switch (op) { case '+': return x + y; case '-': return x - y; case '*': return x * y; case '/': return x / y; case '%': return x % y; default: cout << "calculate(): Unhandled case \n"; return 0; } } int main() { cout << "Enter An Interger \n"; int x; cin >> x; cout << " Enter Another Interger \n"; int y; cin >> y; cout << "Enter an operator (+,-,*,/,%) \n"; char op; cin >> op; return 0; }
4 Answers
+ 3
Ok, So here's your fault:
1. You did not call the function
2. You didn't break; cases, each case must be broken except for default
3. you have more than 1 return in that function, better if you use a variable to store the case result and then return it.
here's the fixed version:
http://pastebin.com/KS6inNXk
+ 2
You're not calling calculate(...)
+ 2
i called the function and worked
0
what if i want this calculator to ask user inpute continuously?? what to add there?