title: if my scanf variable is a float and a user inputs a character how can i prompt them to input a number? assuming the scanf is inside a do while loop
body: <p>i have tried to use k = getchar() but it doesn't work too;</p>
  
  <p>here is my code</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main()
  {
      float height;
      float k=0;
      do 
      {
          printf("please type a value..\n");
          scanf("%f",&amp;height);
          k=height;
      }while(k&lt;0);// i assume letters and non positive numbers are below zero.
      //so i want the loop to continue until one types a +ve float.
      printf("%f",k);
  
  
  
      return 0;
  }
  </code></pre>
  
  <p>i want a if a user types letters or negative numbers or characters he/she should be prompted to type the value again until he types a positive number</p>