do
{
cout << "Height: ";
cin >> height;
cin.ignore(1000,'\n');
if (height <= 25 || height >= 110)
{
cout << "***** Invalid height; please enter a "
"height in inches between 24
and 110.*****" << "\n";
}
}while (height <= 25 || height >= 110);
This code works fine when I enter a number, but if a letter is entered the loop will not end. It stays in the loop outputs Height: , then outputs my invalid height statement and then outs Height: , and then invalid statement over and over. I declared height as an int and am not sure what's really happening when a letter is entered. Not quite sure what I need to do to make the loop not run infinitely if a letter is entered. Any suggestions? thanks
if(heightOk && weightOk)
{
cout << "\nThe candidate has been ACCEPTED!" << "\n\n\n";
acceptedCount = acceptedCount + 1;
}
else if (heightOk && !weightOk)
{
cout << "\nThe candidate has been rejected based on WEIGHT"
" requirement." << "\n\n\n";
}
else if (weightOk && !heightOk)
{
cout << "\nThe candidate has been rejected based on the "
"HEIGHT requirement." << "\n\n\n";
}
else
{
cout << "\nThe candidate has been rejected based on the"
" HEIGHT and WEIGHT requirement." << "\n\n\n";
}
}
Thanks rich that worked! I had never heard of that, I was thinking that it had something to do with enter a letter into data type int but didn't know what to do. Thanks again!