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; }

3rd Dec 2016, 12:54 PM
Adam Jumanne
Adam Jumanne - avatar
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
3rd Dec 2016, 1:04 PM
Nedim Kanat
Nedim Kanat - avatar
+ 2
You're not calling calculate(...)
3rd Dec 2016, 1:05 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
i called the function and worked
3rd Dec 2016, 1:19 PM
Adam Jumanne
Adam Jumanne - avatar
0
what if i want this calculator to ask user inpute continuously?? what to add there?
3rd Dec 2016, 2:01 PM
Adam Jumanne
Adam Jumanne - avatar