【发布时间】:2015-01-06 05:34:34
【问题描述】:
我正在尝试制作一个简单的程序来计算体重指数,但无论我尝试什么,scanf(s) 总是返回 0.00000。我到处寻找,尝试了很多东西, 谢谢大家。
#include <stdio.h>
#include <stdlib.h>
int main() {
float height;
float initialheight;
float weight;
float bmi;
float nothing;
printf("What's your weight? ");
scanf("%lf", &weight);
printf("%f", &weight);
printf("What's your height? ");
scanf("%lf", &initialheight);
printf("%f", &initialheight);
height = (initialheight * initialheight);
printf("%f", &height);
bmi = (weight / height);
printf("Your BMI is ");
printf("%f", &bmi);
scanf("%f", nothing); //just to keep the program open
return 0;
}
【问题讨论】:
-
为什么不检查scanf的返回值?
-
编译时出现警告。
标签: c floating-point int printf scanf