Consider the simple following example:
do
{
scanf("%d", &number);
if ((number != 1) && (number != 2) && (number != 3) && (number != 4) && (number != 5))
printf("Your number is out of range\n ");
} while ((number != 1) && (number != 2) && (number != 3) && (number != 4) && (number != 5));
- ommit the syntax mistakes --
Basically you are validating the input of a number which is correct if in range 1 to 5 (inclusive). When a number such as -12 or 15 is entered, an error message is printed and loop repeats.
The problem is when you input a character (e.g. a) - visual c++ goes into an endless loop and never stops!
Does anybody know how to correct this - simplest answer please
It works if number is declared as char, scanf changed to scanf %c and ' ' single quotation marks are used around the numbers.
Is there any other way ? - if u know sort me out
This is a very weird case and it only happeneds to me in visual c++ 6.0
Any suggestions ?



LinkBack URL
About LinkBacks


