error check against strings or char

cout<<"What day (Numerics) does your semester start in January?"<<endl;

while (true)
{
cin>>first_day;

if ((cin) && (first_day >= 1) && (first_day <=31))
break;

cin.clear();
cin.ignore( 1000, '\n' );
cout << "you must enter a number 1-31 corresponding to the day you started in January " << flush;
}
Checks against characters...only allows numbers
What would check against strings or char say if I prompted user for specific month?

And could you explain why so I understand without just getting an answer

Thanks
-Collin
Last edited on
Checking chars and strings is a bit different as it is always possible to read into one of the those if there is data present. Though an int can only store a number, a character or string can store anything you type. Checking the string would require some work if you wanted to allow different inputs, but in the simplest cases usually just involves several if statements checking allowable inputs.
Topic archived. No new replies allowed.