Writing a single player battleship, need help with the start game

Trying to make it when I start the game I have to choose either 1 for new game, 2 for load game or 3 to quit program. When I type letters into the code if have now it runs just keeps looping, or if if type in for example 8888882 it loads the game, is there a way to just accept 1 2 3?

char start_game ()
{
char choice;
cout << "Welcome to Battleship!\n1) Start New Game\n2) Load Game\n3) Quit\n\n";
cin >> choice;

while (choice != '1' && choice != '2' && choice != '3')
{
cin.clear();
cin.ignore(999,'\n');
cout << "Please enter 1,2, or 3: ";
cin >> choice;
}
return choice;
}
Last edited on
Topic archived. No new replies allowed.