I just started to make my way in c++ and i'm trying to build a calculator.
everything is working fine except my "if" and "else" in case 4. it would be nice if anyone could help me and explain what i did wrong.
(i didn't include all my lines so it would be more clean)
1 2 3 4 5 6 7 8 9 10 11 12
switch(userChoice)
{
case'4':
cout << "enter number you want to divide " << X << " by" <<endl;
cin >> Y;
cout << " " << endl;
if(Y = 0) {cout << "ERROR";
}
else
{cout << "the result is " << (X / Y);
}
break;
void calc()
{
//Here is all actual calculation code which was previously in main()
}
int main()
{
char choice;
do {
calc();
std::cout << "do you want to calculate something else? Y/N\n";
std::cin >> choice;
//Additional input and lowercase handling optional
} while(choice == 'Y');
}