Friday, April 20, 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

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...