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