im a begginer making a calculator application and recently switched the mess of else if statements to one switch case. for some reason, now the 'e' option (supposed to exit the program) outputs the following:
select operation
([a]ddition, [s]ubtraction, [d]ivision, [m]ultiplication, [p]ower, [S]quare root, [e]xit)
e
type in 2 numbers (1 if sqrt): ```
this is the code.
``` #include <iostream>
#include <cmath>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
int calcs() {
cout << "select operation" << endl << "([a]ddition, [s]ubtraction, [d]ivision, [m]ultiplication, [p]ower, [S]quare root, [e]xit)" << endl;
char operation;
cin >> operation;
cout << "type in 2 numbers (1 if sqrt): ";
double num1{ 0 }, num2{ 0 };
cin >> num1 >> num2;
cout << endl;
switch(operation){
case 'a':
cout << num1 + num2 << endl << endl;
break;
//[here enters various cases (message is too long)]
case 'e':
return 0;
default:
std::cerr << "unknown command" << endl << endl;
break;
}
return 1;
}
int main() {
while (calcs()) {} //makes it so the program loops until user iputs 'e'
return 0;
} ```