
Answers 229
Answer 27: The problem is that “1” is an integer. The number “3” is also an
integer. So “1/3” is an integer divide.
Thus, the statement:
12 result = 1/3; // Assign result something
does an integer divide of 1 by 3. Integer divides truncate the fractional
part so the result is 0. The integer “0” is turned into floating-point and
assigned result.
The programmer should have written this as:
12 result = 1.0 / 3.0;// Assign result something
Answer 28: The
scanf
function is extremely tricky to use. In this program the
statement:
22 scanf("%c %d", &oper, &value);
gets a character and a integer. The next time
scanf
is called, it will read
another ...