Hi, I am fairly new with c++ and I would really appreciate any help right now.
So my question goes like this, can switch case function ask/run the statement again if the user inputs a wrong choice. Or if it does not, what options do i have? Thanks in advance
I suggest a function to prompt the user for their choice, then the switch statement.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
char getChoice()
{
char result;
while (true) {
cout<<"Choose the corresponding number of what you want to MEASURE:" << endl
cout<<"[1] Distance"<<endl;
cout<<"[2] Volume"<<endl;
cout<<"[3] Temperature"<<endl;
cout<<"Enter choice: ";
if (cin>>result &&
result >= '1' &&
result <= '3') {
cout<<endl;
return result;
}
}
}
You could even make the printed text a parameter. That way you could use the same function for other menus like lines 22-28