0

Does Anyone Know Why This Code Is Printing The Number Ten??

I'm having an issue with making a calculator in C++. The calculator itself is working, however, after the calculation, the program prints the number ten to the screen and I have no idea why. Can someone help me out? #include <iostream> using namespace std; int calculator(){ int a, b; char op; cout << "Enter Operator, Either +, -, *, or /: "; cin >> op; cout << "Enter Two Numbers: "; cin >> a >> b; switch (op) { case '*': cout << a * b << endl; cin.get(); break; case '/': cout << a / b << endl; cin.get(); break; case '+': cout << a + b << endl; cin.get(); break; case '-': cout << a - b << endl; cin.get(); break; } } int factorial(int n){ if (n==1){ return 1; } else { return n * factorial (n-1); } } int main() { cout << calculator(); cout << endl; cout << factorial(4); return 0; }

11th Aug 2017, 4:19 AM
DinoBambino
4 odpowiedzi
+ 9
https://code.sololearn.com/cpAv6vQs0Itk/?ref=app int calculator() should be void calculator() as it never returns a value.
11th Aug 2017, 5:37 AM
jay
jay - avatar
+ 5
What is your input to the program?
11th Aug 2017, 5:00 AM
Bàng Tứ Cường
Bàng Tứ Cường - avatar
+ 3
'Enter operator............. And enter two numbers :24' Is being printed all the time I run it for any two integers .
11th Aug 2017, 5:46 AM
Omniscient
Omniscient - avatar
+ 1
Thank you Jay! Works perfect now. I really appreciate it
11th Aug 2017, 6:00 AM
DinoBambino