Hi everyone,
Why does this line of code produce an infinite loop upon receiving invalid input, and how do I fix it?
I am just trying to prompt the user for input until myDouble is, in fact, a double (i.e. when the scanf() function returns non-zero). I get similar results using a do ... while loop:Code:for (int i = 0; !i; i = scanf("%lf", &myDouble)) puts("Please enter a double: ");
Code:do { puts("Please enter a double: "); } while (!scanf("%lf", &myDouble));