-
Help Please
hi, could someone give me some tips on how can i make the repeat if false has occur.
for example: the program must read in positive integer but if user enter incorrect type data, the computer will ask the user to re-enter number. can someone help me on this? please/
-
Code:
bool ok = false;
int num;
while(!ok)
{
while(!(cin >> num))
{
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter integer: ";
}
if(num < 1)
{
cout << "Enter positive number!";
}
else
{
ok = true;
}
}
-
Read the FAQ, I'll bet you anything it's in there somewhere. And read this while you're at it.