title: C++ Do-While infinite loop even if the condition is satisfied (can't understand why)
body: <p>I have been searching for hours an issue similar to the one I'm experiencing right now, but I can't find anything, nor here nor in other websites.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      double Numero=0, ParteDecimale=0, Controllo=0, Controllo2=0;
      int ParteIntera=0;
      string Var1="1", Var0="0", NumeroFinale;
      cout&lt;&lt;"\n\n\tBenvenuto, questo programma ti consente di convertire la parte\n"
            "\tdecimale di un numero in sistema binario. Per iniziare, inserisci un numero: ";
      cin&gt;&gt;Numero;
      cout&lt;&lt;Numero&lt;&lt;" Numero\n\n"&lt;&lt;endl; //
      ParteIntera=Numero; //casting implicito, in modo da poter isolare esclusivamente la parte decimale del numero inserito.
      cout&lt;&lt;ParteIntera&lt;&lt;" ParteIntera\n\n"&lt;&lt;endl; //
      ParteDecimale=Numero-ParteIntera; //Isolamento della parte decimale
      cout&lt;&lt;ParteDecimale&lt;&lt;" ParteDecimale\n\n"&lt;&lt;endl; //
      Controllo2=ParteDecimale;
  
  do{
      ParteDecimale=ParteDecimale*2; //Moltiplicazione della parte decimale per due
      cout&lt;&lt;"\n\nParteDecimaleCiclo "&lt;&lt;ParteDecimale&lt;&lt;endl; //
  
  
  
      if(ParteDecimale&lt;1){
          NumeroFinale=NumeroFinale+Var0;
          cout&lt;&lt;"\n\nNumeroFinaleMin1 "&lt;&lt;NumeroFinale&lt;&lt;endl; //
      }
      else{
          NumeroFinale=NumeroFinale+Var1;
          cout&lt;&lt;NumeroFinale&lt;&lt;" NumeroFinaleMagg1\n\n"&lt;&lt;endl; //
          ParteDecimale-=1;
          cout&lt;&lt;ParteDecimale&lt;&lt;" ParteDecimaleMagg1\n\n"&lt;&lt;endl;
      }
      Controllo=ParteDecimale;
      cout&lt;&lt; "\n\nCONTROLLO " &lt;&lt;Controllo; //
      cout&lt;&lt;"\n\nNUMERO "&lt;&lt;Numero; //
    }
    while(Controllo!=Controllo2);
  
  cout&lt;&lt;NumeroFinale&lt;&lt;endl; 
  }
  </code></pre>
  
  <p>Sorry if the code is messy, but when I saw that it was not working as expected I decided to output every value to follow along with the process, and that's the weird thing.. The code acts exactly as expected and the results are all right, it just refuses to exit the do-while loop even if the condition is satisfied.</p>
  
  <p>For example:</p>
  
  <p>-I input "12.2", the program store the number inside the "ParteIntera" variable (which is an int, I'm doing that to remove the decimal part);</p>
  
  <p>-It stores "Numero-ParteIntera" inside "ParteDecimale" (Numero is the input I entered at the beginning), and at this point "ParteDecimale" is equal to 0.2;</p>
  
  <p>-The value of "ParteDecimale" is stored inside "Controllo2";</p>
  
  <p>-Here starts the Do-While loop, that basically does "ParteDecimale*2", so it's "0.4";</p>
  
  <p>-It checks if ParteDecimale is bigger or smaller than 1, and based on this it executes the istructions inside the if statements;</p>
  
  <p>-The value of "ParteDecimale" that is obtained from the if statement is then stored inside "Controllo" (In this case it's 0.4);</p>
  
  <p>-The condition is checked, in this case "Controllo" and "Controllo2" are still different so the loop starts over;</p>
  
  <p>At a certain point ParteDecimale will be 0.6, so when the loop starts ParteDecimale become 1.2 (0.6*2). Since it's bigger than 1, the else statement is executed and ParteDecimale become 0.2 (1.2-1). At this point "Controllo" and "Controllo2" are both 0.2, so the condition inside the do-while is not satisfied anymore and the loop should end.</p>
  
  <p>BUT</p>
  
  <p>I can't understand why, it is not ending. If you run the code you will see (you have to quickly click somewhere inside the cmd to temporarily stop the loop) that all the steps are right, probably it's a stupid mistake or something I can't see, but right now I don't know where to bang my head anymore. </p>
  
  <p>Thanks for reading this very long post, any help is appreciated, and sorry for my bad english!</p>