title: Simple greedy algorithm. Infinite loop
body: <p>I wrote a simple greedy algorithm, but somehow it doesn't work. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;conio.h&gt;
  
  int main(void)
  {
      float change;
      std::cout &lt;&lt; "Change: ";
      std::cin &gt;&gt; change;
      int quantity = 0;
      while(change &gt; 0.0){
          if(change &gt;= 0.5){
              change -= 0.5;
          }
          else if(change &gt;= 0.25){
              change -= 0.25;
          }
          else if(change &gt;= 0.1){
              change -= 0.1;
          }
          else if(change &gt;= 0.05){
              change -= 0.05;
          }
          else if(change &gt;= 0.01){
              change -= 0.01;
          }
          quantity++;
          std::cout &lt;&lt; change &lt;&lt; std::endl;
      }
      std::cout &lt;&lt; quantity &lt;&lt; std::endl;
      _getch();
      return 0;
  }
  </code></pre>
  
  <p>While it works for 0.5 and 0.25 it doesn't for 0.01 or 0.1 for example. (it looks like it returns some really small number)
  I can't see where the problem is.</p>
  
  <p>//EDIT
  Converted everything to int values to avoid problem mentioned below <a href="http://en.wikipedia.org/wiki/Zeno%27s_paradoxes#Dichotomy_paradox" rel="nofollow">Zeno</a></p>