Friday, 20 April 2018

c++ - Illogical results of my program

I'm trying to solve this exercise :




Converts floating point number into decimal.
e.g if input is 12.345 then output should be 12345



... so this is my solution :



double d=0;
cout<<"Enter a double : ";
cin>>d;


while(d-(int)d > 0.)
d*=10;

cout<<"Result : "<


I think that algorithm is correct theoretically,
but practically some values not work for me !!



for example :




1.123 work correctly and the program gives 1123,



but 1.12 doesn't work and gives infinite loop !!



where is the problem and what is the solution to make my program work correctly ?

No comments:

Post a Comment

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...