While tidying up the code on my latest project i decided its about time i learnt to check that the user is inputting the correct data. my understanding of the return value of scanf is an int to the value of he number of items read in. ie
scanf("%d", &a); will return 1. if the user just hit enter scanf would sit there waiting for a number to be entered.
if the above is correct why is this an infinite loopCode:int main() { int a, b, x; printf("please enter 2 numbers between 1 and 10 "); x = scanf(" %d %d", &a, &b); while (x != 2) { printf("incorrect input please enter 2 numbers between 1 and 10 "); x = scanf(" %d %d", &a, &b); } return 0; }
coop