计算体重指数。 身体质量指数将您的体重与身高进行比较,计算方法是将体重以千克除以身高(以米为单位)。它给你一个关于你是否体重不足,体重健康,超重或肥胖的想法。如何使用函数计算BMI?
身体质量指数分类:
- 体重不足= < 18.5
- 正常体重= 18.5-24.9
- 超重= 25-29.9
- 肥胖= 30 BMI或更大
如果您体重不足或超重或肥胖,请根据您的身高和年龄确定理想体重。
估计理想体重使用迪瓦恩公式(公斤):
男性:IBW = 50 kg + 2.3 kg for each inch over 5 feet.
女性:IBW = 45.5 kg + 2.3 kg for each inch over 5 feet.
#include <stdio.h>
#include <stdlib.h>
double calculateBMI(double weight, double height);
int main(void)
{
printf("Calculate your BMI\n"); //Calculation of body mass index (BMI)
double w, h, ret;
double BMI = w/(h*h);
ret = calculateBMI(BMI);
printf("Enter your weight in kilograms:\n", w); //Input your weight in kilograms here
scanf("%lf", &w);
printf("Enter your height in metres:\n", h); //Input your height in metres here
scanf("%lf", &h);
printf("Your BMI is %lf\n", ret)
printf("BMI categories:\n");
if (BMI < 18.5)
{
printf("Your BMI is %lf and you are currently underweight.\n");
}
else if (BMI >= 18.5 && BMI <= 24.9)
{
printf("Your BMI is %lf and you are normal weight.\n");
}
else if (BMI >= 25 && BMI <= 29.9);
{
printf("Your BMI is %lf and you are currently overweight.\n");
}
else (BMI >= 30);
{
printf("Your BMI is %lf and you are obese.\n");
}
return 0;
}
double calculateBMI(double weight, double height)
{
double result;
result = weight/(height*height);
return result;
}
帮助我还是不知道该怎么办的职能。请帮帮我。
什么是你遇到的问题?你的问题是什么? –
我有问题,我的功能和回报。你能帮我指出我做错了什么,并加强我的编码吗? –
对于初学者而言,您实际上不会在任何地方*致电*您的功能。要继续使用带有格式化代码的'printf',它需要参数,但不提供这些参数(导致*未定义行为*)。最后,你使用了很多变量而没有被初始化(再次导致未定义的行为)。 –