Hey all,
Having trouble verifying an input is an integer. It's like this:
I need to enter a number, and then check whether it's between 5 and 26, if so, it's acceptable, if not, it runs again to re-input the number after returning an error message.
I have the verification of the numbers down, it's super easy, but I can't get it to re-run the loop when I enter something like: a, or a /.
Instead, it acts like an infinite loop is occuring, which is doesn't make sense, so I'm guessing it has something to do with the int data type and causing overflow issues?
Code segment is here:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
int grid_size;
cin >> grid_size;
//checks that the grid is in the specified range of the project
//if outside the range, error message is dispayed, and input is repeated.
while ((grid_size > 26)||(grid_size < 5)||(isalpha(grid_size))
||(!isalnum(grid_size)))
{
cout << "\nError: Grid number not within defined limits.\n"
<< "Please re-enter the grid size. Remeber that the\n"
<< "size must be in the range 5-26!\n\n";
cin >> grid_size;
}
|
Again, what I have should be working, logic wise. It checks if the number is less than 5, greater than 26, an alphabet character, or neither an alphabet character or numeric. If any of those are true, it should run the loop again, but instead I'm getting this crazy infinite loop if the input is anything but a number.
How do I fix this?
Thanks,
-Drew