title: Non-numerical input causes endless loop
body: <p>For some reason, if the user inputs the wrong data type, such as 'j' or '%', the loop will stop asking for input and will keep displaying <code>"Enter an integer &gt;"</code> over and over. How can I make the program handle bad inputs? And why does entering a non-numerical value cause such strange behavior?</p>
  
  <pre><code>#define SENTINEL 0;
  int main(void) {
    int sum = 0; /* The sum of numbers already read */
    int current; /* The number just read */
  
    do {
      printf("\nEnter an integer &gt; ");
      scanf("%d", &amp;current);
      if (current &gt; SENTINEL)
        sum = sum + current;
    } while (current &gt; SENTINEL);
    printf("\nThe sum is %d\n", sum);
  }
  </code></pre>