title: I need to write a dispense change program.I completed the code,but it has some problem.Please help me to debug the code
body: <p>There is a question in "Problem Solving and Program Design in C" book.I wrote the code, but loop isn't terminating.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  void change(double coin_change, int *quarters, int *dimes, int *nickels, int *pennies);
  int main(void)
  {
      int c_dollars, c_quarters = 0, c_dimes = 0, c_nickels = 0, c_pennies = 0;
      double a_paid, a_due, m_change, coin_change;
      printf("Enter the amount paid&gt; ");
      scanf("%lf", &amp;a_paid);
      printf("Enter the amount due&gt; ");
      scanf("%lf", &amp;a_due);
      m_change = a_paid - a_due;
      c_dollars = floor(m_change);
      coin_change = m_change - floor(m_change);
      // shows coin change
      printf("\n%f\n", coin_change);
      change(coin_change, &amp;c_quarters, &amp;c_dimes, &amp;c_nickels, &amp;c_pennies);
      printf("Change is dollars: %d$, quarters: %d, dimes: %d, nickels: %d,\
  pennies: %d", c_dollars, c_quarters, c_dimes, c_nickels, c_pennies);
      return(0);
  }
  void change(double coin_change, int *quarters, int *dimes, int *nickels, int *pennies)
  {
      int q = 0, d = 0, n = 0, p = 0;
       do{
          if(coin_change &gt;= 0.25){
              q++;
              *quarters = *quarters + q;
              coin_change = coin_change - q*0.25;
          }
          else if( coin_change &gt;= 0.10){
              d++;
              *dimes = *dimes + d;
              coin_change = coin_change - 0.1;
          }
          else if( coin_change  &gt;=  0.05){
              n++;
              *nickels = *nickels + n;    
              coin_change = coin_change - (n*0.05);
          }
          else if(coin_change &gt;= 0.01){
              p++;
              *pennies = *pennies + p;
              coin_change = coin_change - (p*0.01);
          }
      }while(coin_change&gt;0);
  }
  </code></pre>
  
  <p>Thank you,
  I solved problem.The proper code is</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  void change(double coin_change, int *quarters, int *dimes, int *nickels, int *pennies);
  int main(void)
  {
      int c_dollars, c_quarters = 0, c_dimes = 0, c_nickels = 0, c_pennies = 0;
      double a_paid, a_due, m_change, coin_change;
      printf("Enter the amount paid&gt; ");
      scanf("%lf", &amp;a_paid);
      printf("Enter the amount due&gt; ");
      scanf("%lf", &amp;a_due);
      m_change = a_paid - a_due;
      c_dollars = floor(m_change);
      coin_change = (int)((m_change - floor(m_change)) * 100 + 0.5);
      // shows coin change (int)((m_change - floor(m_change)) * 100 + 0.5)
      //coin_change = coin_change * 100;
      printf("\n%f\n", coin_change);
  
      change(coin_change, &amp;c_quarters, &amp;c_dimes, &amp;c_nickels, &amp;c_pennies);
      printf("Change is dollars: %d$, quarters: %d, dimes: %d, nickels: %d,\
  pennies: %d", c_dollars, c_quarters, c_dimes, c_nickels, c_pennies);
      return(0);
  }
  void change(double coin_change, int *quarters, int *dimes, int *nickels, int *pennies)
  {
      int q = 1, d = 1, n = 1, p = 1;
       do{
          if(coin_change &gt;= 25){
              *quarters = *quarters + q;
              coin_change = coin_change - 25;
          }
          else if( coin_change &gt;= 10){
              *dimes = *dimes + d;
              coin_change = coin_change - 10;
          }
          else if( coin_change  &gt;=  5){
              *nickels = *nickels + n;    
              coin_change = coin_change - 5;
          }
          else if(coin_change &gt;= 1){
              *pennies = *pennies + p;
              coin_change = coin_change - 1;
          }
      }while (coin_change &gt;= 1);
  }
  </code></pre>