Pls help, t doesnt give result | Sololearn: Learn to code for FREE!

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

c++

12/3/2016 12:54:12 PM

Adam Jumanne

4 Answers

New Answer

+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?