Hi everyone. The problem I have looks very stupidly at the first sight and I am sorry for posting it. But even if I searched reference manuals and already posted questions in forums around the net, I wasn’t able to solve that.
Could you anyone please tell me, why this isn’t working?
Code:
int nr,err;
do {
printf("\nenter a number (0-10):");
err=scanf("%d",&nr);
if(err==1&&(nr<0||nr>10)) printf("the number must be between 0 and 10\n");
}while(err!=1||(err==1&&(nr<0||nr>10)));
It works fine when you enter a good value, it works also when you enter wrong value, but digit. If you enter a character, it will start an unending repeating. Why doesn’t it ask to reenter the value?
The only tips I’ve found was about flushall() function; I am not sure if it would be usable in my case too, but I can’t use that either – I have to do this in C not in C++.
Thanks for any tips or links somewhere where relevant information could be found.