while(true)
{
unsigned int option;
cout<<"1 - Display the list\n";
cout<<"2 - Add a game title to the list\n";
cout<<"3 - Remove a game title from the list\n";
cout<<"4 - Exit\n";
cin>>option;
if(option == 1)
{
if(gameTitles.empty())
{
cout<<"\nThere are no games to be displayed. Please try again after adding some games to the list.\n";
}
else
{
for(iter = gameTitles.begin(); iter != gameTitles.end(); ++iter)
{
cout<<*iter<<endl;
}
}
}
else if(option == 2)
{
cout<<"\nEnter the game's title:\n";
cin>>newGame;
gameTitles.push_back("newGame");
}
else if(option == 3)
{
cout<<"\nEnter a game to be removed:\n";
cin>>removeGame;
theIterator = find(gameTitles.begin(),gameTitles.end(),removeGame);
theIterator = gameTitles.erase(theIterator);
}
else if(option == 4)
{
break;
}
else
{
cout<<"\nThe option is illegal. Please try again.\n";
}
}
When I choose any 1, 3, 4 or illegal option, the loop brings me to the top and I have possibility to choose again. The problem arises when I am trying to use 2nd option. I just enter in an infinite loop. But I want to enter a game title and after it is added to my vector (I declared it earlier) and then have possibility to choose an option again.
gameTitles.push_back("newGame")switchstatement?gameTitles.push_back(newGame)(leave out the quotes).