title: While loop misbehaving,
body: <p>i am pretty new to c, i m trying to make the user input a number, but if they input a letter or word it shows a warning and asks for input again, my code works fine if the user puts in a number but it goes into an infinite loop if the user inputs something invalid, here is my code</p>
  <pre><code>   #include &lt;stdio.h&gt;
  
  
      int main(void) {
        float salary;
        int status = 0;
        
        while (status == 0)
        {
          printf(&quot; Please input your yearly salary to calculate taxes: \n&quot;);
          status = scanf(&quot; %f&quot;, &amp;salary);
          if (status == 0)
           printf(&quot;invalid input!\n&quot;);
        } 
        printf(&quot;%.2f\n&quot;, salary);
        return 0;
      }
  </code></pre>
  <p>i thought that i was something to do with the buffer left over from the first scanf , but adding a space &quot; %f&quot; didnt work, i tried using fflush(stdin) after then scanf also didnt work. i m not sure what else i can try.</p>
  <p>thanks in advance for any help.</p>