Maybe
Code:
int main()
{
int selection;
string input;
bool done = false;
cout << "Welcome to the employee database, what would you like to do?" << endl // prompt
<< "1. Add an employee" << endl << "2. Modify an employee" << endl
<< "3. Exit the program" << endl;
while ( !done )
{
getline(cin, input); //get input
stringstream(input) >> selection; //extract selection integer
if (selection == 1)
{
employees.push_back(create());
}
else if (selection == 2)
{
cout << "Enter the name of the employee you'd like to edit: ";
getline(cin, input);
get_employee(input).edit();
}
else if (selection == 3)
{
done = true;
}
else
{
cout << "Please enter a valid selection, 1 or 2." << endl;
}
}
}
return 0;
}
Good input is really determined by something like this, not by the user typing in another number.
Code:
if ( getline(cin, input) && stringstream(input) >> selection ) {
// do your thing
} else {
// either cin failed (say eof), or what was typed wasn't an integer)
// if cin has failed, then set done to true
}