gcc - C simple program doesn't work -
hello everyone! i'm trying learn c language , have trouble:
example code book works should work:
#include <stdio.h> /* печать таблицы температур по Фаренгейту и Цельсию для fahr = 0, 20, ..., 300 */ main() { int fahr, celsius; int lower, upper, step; lower = 0; /* нижняя граница таблицы температур */ upper = 300; /* верхняя граница */ step = 20; /* шаг */ fahr = lower; while (fahr <= upper) { celsius = 5 * (fahr-32) / 9; printf("%d\t%d\n", fahr, celsius); fahr = fahr + step; } }
output:
0 -17
20 -6
40 4
60 15
80 26
100 37
120 48
140 60
160 71
180 82
200 93
220 104
240 115
260 126
280 137
300 148
but code i've written doesn't anything!:
#include <stdio.h> main() { int fahr, celsius, lower, upper, step; printf("enter lower temperature:"); scanf("%d", &lower); printf("enter upper limit:"); scanf("%d", &lower); printf("enter step:"); scanf("%d", &lower); fahr = lower; while (fahr <= upper) { celsius = 5 * (fahr-32) / 9; printf("%d\t%d\n", fahr, celsius); fahr = fahr + step; } }
output:
$ gcc fahr.c -o fahr.out
$ ./fahr.out
enter lower temperature:0
enter upper limit:300
enter step:20
$
what's wrong?
all of scanfs read variable lower.
scanf("%d", &lower);
this typical when copy , paste sections of code. welcome c hope grow love as rest of us.
Comments
Post a Comment