I always put default
at the end of all cases and it works, however, today I ran this chunk of code and my default is not working. I put it in other possible locations to check if it would work but it didn't. It is running all fine except for when I take a user input that does not match the cases I made. Can anyone please tell me whats wrong with the code or how can I make default statement work?
int main(){
int selection;
do
{
cout << "Please make a selection: \n";
cout << "1) Addition\n";
cout << "2) Subtraction\n";
cout << "3) Multiplication\n";
cout << "4) Division\n";
cin >> selection;
} while (selection != 1 && selection != 2 && selection != 3 &&
selection != 4);
switch (selection)
{
case 1:
cout << "you want addition\n";
break;
case 2:
cout << "you want subtraction\n";
break;
case 3:
cout << "you want multiplication\n";
break;
case 4:
cout << "you want division\n";
break;
default:
cout << "you entered wrong operation\n";
break;
}
cout << "You selected option #" << selection << "\n";
system("pause");
return 0;
}