实际上,我正在做bmi计算器。在那里我想计算以英寸为单位的身高和以磅为单位的体重指数,也需要以厘米为单位的身高和以公斤为单位的体重的正确公式。
我试过了,但无法计算出如下所示的范围的实际值。超出范围。
BMI类别:
* Underweight = <18.5
* Normal weight = 18.5-24.9
* Overweight = 25-29.9
* Obesity = BMI of 30 or greater发布于 2010-06-13 21:19:55
在这里(这里假设您的原始值是ints -您可以轻松地使用浮点数,而不会有任何问题):
// Metric
int heightInCms;
int weightInKgs;
// Imperial
int heightInInches;
int weightInPounds;
float height; // metres
float weight; // kilograms
// Unit Conversions
height = (float) heightInCms * 0.01;
weight = (float) weightInKgs;
height = (float) heightInInches * 0.0254;
weight = (float) weightInPounds * 0.4536;
float BMI = weight / (height * height);
if (BMI < 18.5) {
// Underweight
}
else if (BMI < 25.0) {
// Normal
}
else if (BMI < 30.0) {
// Overweight
}
else {
// Obese
}发布于 2010-06-13 20:33:31
使用英制单位的BMI:
BMI = weight(lb) x 703 / height(in)^2参考文献:BMI on Wikipedia
发布于 2010-06-13 20:55:57
我只是猜测你的问题是关于浮点数和整型的。您必须确保对浮点数使用CGFloat权重,以便它可以包含浮点数
然后你就会做很多如果不是的话
CGFloat BMI = weight(lb) x 703 / height * height
if (BMI <= 18.5)
NSLog(@"Under weight");https://stackoverflow.com/questions/3032219
复制相似问题