我正在尝试制作一个BMI计算器。我犯了多个“未声明的标识符”错误,即使我犯了这些错误?
#include <stdio.h>
int main(void)
{//main method
//Ex 2.32
printf("Ex 2.32: Body Mass Index Calculator\n\n");
int weightInPounds;
int heightInInches;
int bmi;
//displays title
printf("Body Mass Index Calculator\n");
//user input for weight
printf("Please input your weight in pounds:\n");
scanf("%d", &weightInPounds);
//user input for height
printf("Please input your height in inches:\n");
scanf("%d", &heightInInches);
//caluclate BMI
bmi = (weightInPounds * 703) / (heightInInches*heightInInches);
printf("\n");
//display BMI categories
printf("BMI Values\n");
printf("Underweight: less than 18.5\n");
printf("Normal: between 18.5 and 24.9\n");
printf("Overweight: between 25 and 29.9\n");
printf("Obese: 30 or greater\n\n");
//display user BMI
printf("Your BMI is: %d", &bmi);
//end Ex 2.32
}//end main function
最佳答案
我测试了您的代码,效果很好!代码中有错误,例如:
printf("Your BMI is: %d", &bmi);
您只需要像这样打印它:
printf("Your BMI is: %d", bmi);
关于c - C中的BMI计算器,未声明的标识符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25669722/