Mail Archives: djgpp/1997/03/03/23:50:09
David Tucker (david AT temss2 DOT main DOT temple DOT edu) wrote:
: I have a question.
: When I do a calculation such as:
: X = a / b; // where int a = 994 and int b = 1000
: or
: cout << "X = " << a / b << endl;
: my result is 0.
The integer result is indeed 0 - you can't fit any '1000's into a '994'.
If you are interested in the real result, cast to float (or double for
more accuracy) before dividing. Make sure X is of a floating-point type,
though.
--
George Foot <gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk>
Merton College, Oxford.
- Raw text -