So for my class at school I have to make a menu to display on a kiosk for an amusement park in the future. I'm having trouble with the menu working although I have most of it down. This isn't the first time I did a menu for this class but I have altered it a bit because the other one didn't display an error if the user typed in something that wasn't an option (didn't even think about that being a problem until we talked about it in class today)
void menu()
{
int choice;
cout<<"\t-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-"<<endl;
cout<<"\t /Horacious Glump Ride Interface Menu /"<<endl;
cout<<"\t-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-"<<endl;
cout<<"\t 1 - Add rider to line"<<endl;
cout<<"\t 2 - Run the ride"<<endl;
cout<<"\t 3 - Find wait time"<<endl;
cout<<"\t 4 - Display the line"<<endl;
cout<<"\t 0 - Exit program"<<endl;
cout<<"\t-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-"<<endl;
cout<<"Please enter your selection: ";
cin>>choice;
if(choice==1)
{
menu();
}
elseif(choice==2)
{
menu();
}
elseif(choice==3)
{
menu();
}
elseif(choice==4)
{
menu();
}
elseif(choice==0)
{
Exit();
}
else
{
cin.ignore();
cout<<"** INVALID SELECTION - PLEASE TRY AGAIN **"<<endl;
menu();
}
return;
}
Now for some reason when I try to make the error message display it starts looping it over and over again and it gets stuck doing that infinitely until I close the window myself. Does anyone know what I did wrong?
//Edit:
Also if you could help me out with my placement of cin.ignore and how to use it correctly to dump the answer they gave me that I don't want anymore would be great.
switch(choice)
{
case 1:
// Add Rider Function
break;
case 2:
// Run the ride function
break;
case 3:
// Find wait time function
break;
case 4:
//Display the line function
break;
case 0:
Exit();
break;
};
So I can't remember how to display the error message in a switch if someone types something else. Mind showing me?