![]() |
![]() |
![]() |
![]() |
![]() |
|
Note that you use the %i read specification in scanf calls to
read integers, just as you use %i in printf calls
to display
integers.
By extension, you would think that you would use the %f read
specification in scanf to read double type floating-point
numbers, inasmuch as you use the %f print specification in
printf calls to display such numbers.
Alas, no. The %f read specification works only with those
floating-point
numbers of type float, and
you get weird results if you accidentally use %f with a
floating-point number of type double. For numbers of type
double, you need the %lf read specification:
double price;
...
*------*
| |
| v
| ------
scanf ("%lf", &price);
...
See the hardcopy version of this book for a larger discussion of read specifications.