title: C program counting coins with while loops
body: <p>I've seen this particular C program mentioned quite a bit, albeit in some different forms. However I cannot seem to identify the source of my problem, or find another answer that helps. The program compiles and even executes correctly except for a single input: 4.2</p>
  
  <p>The program appears to count the minimum number of coins needed to make the change entered as input, except for 4.2. It outputs 22 instead of 18 as it should (16 quarters, 2 dimes). 
  Any thoughts?  I'm auditing an online course, no credit/no academic dishonesty issues.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;cs50.h&gt;
  
  int main(void)
  { 
  
  //quarters, dimes, nickels, and total number of coins. a is float input for exact change.
  
  float a;
  int q=0;
  int d=0;
  int n=0;
  int p=0;
  int i;
  
  //petitioning input
  do
    {
    printf("Hello, how much change do I owe you?\n");
    a = GetFloat();
    }
    while(a&lt;=0);
  
  //converting float a to an integer i
  i= a*100;
  
  //four 'while' loops checking quarters nickels dimes pennies and adding to coin count while
  while(i&gt;=25)
      {
      i=i-25;
      q++;
      }
  while(i&gt;=10 &amp;&amp; i&lt;25)
      {
      i=i-10;
      d++;
      }
  while(i&gt;=5 &amp;&amp; i&lt;10)
      {
      i=i-5;
      n++;
      }
  
  while(i&gt;0 &amp;&amp; i&lt;5)
      {
      i= i-1;
      p++;
      }
  
  //printing sum of each coin type 
    {
    printf("%d\n", q+d+n+p);
    }
  return 0;    
   }
  </code></pre>