In the code below I want to only accept input of 1, 2, 3, 4, 5 or 6.
This works in that it will accept only one of those numbers and return it to my main.
If I enter a number such as '22' say, then it reprompts for a correct number; but if I input 'a' it locks the program up.
Is there a better way of asking for my input to stop this happening?
Code:int menu () { int choice=0; cout<<endl<<"JayCee's Player Information Storage, Recall, and Amendment Facility"<<endl<<endl<<endl; cout<<"Please choose from :"<<endl<<endl<<endl; cout<<" 1 - Ceate a new data file"<<endl<<endl; cout<<" 2 - Add a record to an existing file"<<endl<<endl; cout<<" 3 - Delete a record from a file"<<endl<<endl; cout<<" 4 - Read a single record from a file"<<endl<<endl; cout<<" 5 - Read whole file into an array"<<endl<<endl; cout<<" 6 - End the program"<<endl<<endl<<endl; cout<<" Choice - _\b"; while (choice<1 || choice>6) { cin>>choice; } return choice; }