Just starting to learn C and typed in a program from on page 12 of the second edition of Kernighan and Ritchie.
The program is supposed to print a Fahrenheit to Celsius conversion table such as:
0 -17.8
20 -6.7
40 4.4
and so on till it reaches 300 Fahrenheit
The code builds and compiles with no errors, but when it prints in DOS it just keeps repeating the first line 0 -17.8 and does not stop repeating.
The code follows:
#include <stdio.h>
/* print Fahrenheit - Celsius table */
int main(void)
{
float fahr, celsius;
int lower, upper, step;
lower = 0 ; /* lower limit of temperatures table */
upper = 300 ; /* upper limit */
step = 20 ; /* step size */
fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr * step;
}
return 0;
}
Any help on this would be appreciated. I also typed in the program on page 15 (same book) using the #define symbolic constants and get the same exact results.