0

Here is the code that causes the problem:

int n;
do{
printf(/*Message that tells the user to enter an int*/);
}while(scanf("%d", &n) != 1);//Checks that the variable is an int; if not restarts the do while loop and waits for the user input again (at least it's what it's supposed to do)

when the user enters an int, the code continues normally. But if they enter something else, this is repeated infinitely:

    printf(/*Message that tells the user to enter an int*/);

without waiting for the user input again. I don't know what to do now, this problem is driving me crazy (i'm a newbie, so if the question ends up being stupid, i won't be surprised), any help would be welcome! thank you in advance!

  • When the user enters something that doesn't jive with the requested format specifier, the `while` condition trips. Now consider what is *still* in the input stream, repeatedly failing, and repeatedly remaining, with each subsequent invoke to `scanf` . – WhozCraig Aug 27 '21 at 09:54
  • @WhozCraig jive -> jibe – Tom Karzes Aug 27 '21 at 12:34

0 Answers0