basically i need the user to enter two numbers seperated by spaces. these numbers represent year and age respectively.
eg 10 5
if they enter just 10 i need to set year = -1 and age = -1
if they enter characters instead of numbers i also need to store both numbers as -1
the problem i have with my code is that when the user enters just one number and then hits enter, it waits forever for the user to enter another number. i dont know how to get around this using cin, given that it ignores whitespace. i know i could use getline and tokenise but that seems too complicated. any clues?
i have the following code
char year;
char age;
cout<<"What age to search for? =>";
cin>>year;
if(isdigit(year))
{
cin>>month;
if(isdigit(month))
{
s.age[0] = static_cast<int>(year) - 48;
s.age[1] = static_cast<int>(month) - 48;
}
else
{
s.age[0] = -1;
s.age[1] = -1;
}
}
else
{
s.age[0] = -1;
s.age[1] = -1;
}
cin.ignore(100, '\n');

