int
w = 0;int n = 23;
int d = 5;
double x = 0;
cout.setf(ios::scientific);
w = n/d;
x = n/
n=x*d;
when run 'n' comes out to be 2 not 3 like it should be. Everything else worked 'w' is 4 and 'x' is .6. I was just wondering why this would happen. If anyone could help that would be great.
Thanks

Problem with decimals
moondancer10
Do the following:
x = ((double)n) / ((double)d) - ((double)w);
Greetings
Jochen
A. L.
James
maxaeran
It is widely available at the Net. E.g. first search results points to http://docs.sun.com/source/806-3568/ncg_goldberg.html.
In your particular case problem happens because 23/5 cannot be exactly represented as binary floating point number (see section "Floating-point Formats" in the abovementioned document).
Thanks,
Eugene
GAL
Thanks,
James
William Fields
Thanks,
Eugene