对于本实验我不允许编辑主函数,所有操作都必须在main函数下完成。我似乎无法在这里找到我的问题。我认为这与调用calculateBMI函数有关。BMI计算器实验室找不到问题
#include <stdio.h>
FILE *fp;
//For loop, which allows up to 4 entries.
int main(void) {
int i;
fp = fopen("csis.txt", "w");
for (i = 1; i <= 4; ++i) {
calculateBMI();
}
fclose(fp);
return 0;
}
//Function that calculates the BMI of the Input.
double calculateBMI(int weightInPounds, int heightInInches) {
double BMI;
BMI = weightInPounds * 703/heightInInches * heightInInches;
//If BMi is less then 18.5 print this.
if (BMI < 18.5) {
printf("Your BMI is %d, you are underweight.", BMI);
fprintf(fp, "Your BMI is %d, you are underweight.", BMI);
}
//if BMI is between 18.5 and less then 25 print this.
else if (BMI > 18.5 & BMI < 25) {
printf("Your BMI is %d, you are Normal.", BMI);
fprintf(fp, "Your BMI is %d, you are Normal.", BMI);
}
//if BMI is greater then 25 and less then 30 print this.
else if (BMI > 25 & BMI < 30) {
printf("Your BMI is %d, you are Overweight.", BMI);
fprintf(fp, "Your BMI is %d, you are Overweight.", BMI);
}
//if BMI is greater then 30 print this.
else (BMI > 30) {
printf("Your BMI is %d, you are Obese.", BMI);
fprintf(fp, "Your BMI is %d, you are Obese.", BMI);
}
//Asks user for input weight in pounds.
printf("What is your weight in pounds?");
fprintf(fp, "What is your weight in pounds?");
scanf("%d\n", weightInPounds);
fscanf(fp, "%d\n", weightInPounds);
// Asks user for input height in inches.
printf("What is your height in inches?");
fprintf("What is your height in inches?");
scanf("%d\n", heightInInches);
fscanf(fp, "%d\n", heightInInches);
getchar(0);
return (0);
}
无法找到你的“问题”和编译器有太多的警告和错误,您应该按照编译器的通知逐一解决它们。请启用所有编译器警告。 –
对不起,我很匆忙,我是这个论坛的新手。 – Chris