title: What's wrong with my code (CS50 2012 Pset 1 greedy)
body: <p>I am trying to make a program that gives the least amount of coins for change but if I give a number other than something that divides into quarters, it fails miserably. For example, if I input 1.25, I get 5 quarters but if I input 1.26, I get 5 quarters 1 nickel which is of course incorrect. What am I doing wrong?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;cs50.h&gt;
  #include &lt;math.h&gt;
  
  void calculate_change(change_requested){   
          int num_quarters = 0;
          int num_dimes = 0;
          int num_nickles = 0;
          int num_pennies = 0;
  
          int val_quarters = 25;
          int val_dimes = 10;
          int val_nickles = 5;
  
          num_quarters = floor(change_requested/val_quarters);
          if(change_requested % val_quarters != 0){
              num_dimes = floor( (change_requested - (num_quarters * val_quarters))/val_dimes );
              if( change_requested - (((num_quarters * val_quarters) + (num_dimes * val_dimes))) != 0){
                  num_nickles = floor( change_requested - ( (num_quarters * val_quarters) + (num_dimes * val_dimes)/val_nickles ));
                  if( change_requested - (((num_quarters * val_quarters) + (num_dimes * val_dimes) + (num_nickles * val_nickles))) != 0){
                      for(int i = 0; i&lt;change_requested - (((num_quarters * val_quarters) + (num_dimes * val_dimes) + (num_nickles * val_nickles))); i++){
                          num_pennies++;
                      }
                  }
              }
          }
          if(num_quarters &gt; 0){
              printf("%i Quarters ",num_quarters);
          }
          if(num_dimes &gt; 0){
              printf("%i Dimes ",num_dimes);
          }
          if(num_nickles &gt; 0){
              printf("%i Nickles",num_nickles);
          }
          if(num_pennies &gt; 0){
              printf("%i Pennies",num_pennies);
          }
          printf("\n");
  
      }
  
  int main (void){
      printf("How Much Change Do You Need?\nAmount: ");
      float change_requested = GetFloat();
      calculate_change(change_requested * 100);
      return 0;
  }
  </code></pre>