title: scanf ignoring, infinite loop
body: <pre><code>int flag = 0;
  int price = 0;
  while (flag==0)
  {
      printf("\nEnter Product price: ");
      scanf("%d",&amp;price);
      if (price==0) 
          printf("input not valid\n"); 
      else 
          flag=1;
  }
  </code></pre>
  
  <p>When I enter a valid number, the loop ends as expected. But if I enter something that isn't a number, like <code>hello</code>, then the code goes into an infinite loop. It just keeps printing <code>Enter Product price:</code> and <code>input not valid</code>. But it doesn't wait for me to enter a new number. Why is that?</p>