title: C programming. Trying to loop trap a user into entering a positive number
body: <p>Beginner here. I'm trying to trap a user into entering a positive number. However the while loop doesn't seem to be working for when the user enters and incorrect number.</p>
  
  <p>Output:
  </p>
  
  <pre><code>Please enter a positive integer: -3
  I'm sorry, you must enter a positive integer greater than zero: why?
  I'm sorry, you must enter a positive integer greater than zero: -42
  I'm sorry, you must enter a positive integer greater than zero: 42
  The positive integer was : 42
  Press any key to continue....
  </code></pre>
  
  <p>Code:
  </p>
  
  <pre><code>#define _CRT_SECURE_NO_WARNINGS
  #include&lt;stdio.h&gt;
  void clear_keyboard_buffer(void);
  int main()
  {
      int k;
      printf("Please enter a positive integer: ");
      scanf("%d", &amp;k);
      if (k &gt; 0)
      {
          clear_keyboard_buffer();
          printf("The positive integer was: %d ", k);
  
      }
      while (k&lt;=0)
      {
          printf("I'm sorry, you must enter a positive integer greater than zero: ");
          scanf("%d", &amp;k);
          return 0;
      }
  }
  
  void clear_keyboard_buffer(void)
  {
      char ch;
      scanf("%c", &amp;ch);
      while (ch != '\n')
      {
          scanf("%c", &amp;ch);
      }
  }
  </code></pre>