To solve the empty-string-puzzle just change menu into this:
Code:
void menu()
{
string errmsg("ERROR! Reason: could not find valid input.\n");
for( unsigned i = 0; i < RACERS; ++i )
{
cout << "Enter the name of racer #" << i+1 << ": ";
while( !(getline( cin, theRacers[i].sName)) || theRacers[i].sName.size() == 0 )
{
cout<<errmsg;
cout<<"RETRY (did you enter a name?): ";
reset_istream();
}
cout << "Enter the finish time (minutes) of racer #" << i+1 << ": ";
while( !(cin >> theRacers[i].nMinutes) )
{
cout<<errmsg;
cout<<"RETRY (finish time in minutes): ";
reset_istream();
}
reset_istream();
}
}
This code also intercepts input of CTRL-Z/D. That's why the reset_istream() function looks so weird by the way. In this case no terminating character clearance is desired. Otherwise when you try to input a new value, the first terminating character is going to be eaten away.