我在制作 BMI 计算器程序时遇到了问题,我想知道我做错了什么。我是初学者,请放轻松,谢谢!
#include <stdio.h>
main()
{
// Variables for height, weight, and bmi
float height;
float weight;
float bmi;
printf("\aEnter your height: ");
scanf(" %f", height);
printf("\a\nEnter your weight: ");
scanf(" %f", weight);
bmi = (height * 4.88) / (weight * weight);
printf("\a\nYour BMI is: %f", bmi);
getchar();
return 0;
}
最佳答案
scanf 需要一个指向格式字符串后的参数的指针。 这样使用 & 运算符:
printf("\aEnter your height: ");
scanf(" %f", &height);
printf("\a\nEnter your weight: ");
scanf(" %f", &weight);
关于c - 用 C 实现 BMI 计算器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18520692/