在我最近的项目中,简而言之,我正在计算BMI。
我使用一个一维数组来表示体重和身高(双精度类型)
为了计算BMI,我使用了一个函数,其中的方程式作为返回值。
问题是结果远远超出了BMI的值(例如: 20456)
如果是一个可接受的问题,返回BMI计算的结果会是问题的根源吗?
下面是我的代码:
#include<iostream>
#include<Windows.h>
#include<string>
double BMI(double height, double weight);
int main()
{
SetConsoleTitle("Body Mass Index");
double BMIinput [2];
std::string Name;
std::cout << "Enter your height (inches): ";
std::cin >> BMIinput[0];
system("CLS");
std::cin.ignore();
std::cout << "Enter your weight (pounds): ";
std::cin >> BMIinput[1];
system("CLS");
std::cin.ignore();
std::cout << "Enter your name: ";
std::getline(std::cin, Name);
system("CLS");
std::cout << "Name: " << Name << std::endl;
std::cout << "BMI: " << BMI(BMIinput[0], BMIinput[1]) << std::endl;
system("PAUSE");
system("CLS");
return 0;
}
double BMI(double height, double weight)
{
return (height * height / weight) * 703;
}发布于 2016-07-14 04:27:36
BMI是用体重除以身高的平方来计算的。你的程序会计算它的倒数。
发布于 2016-07-14 04:30:39
你的BMI公式是错误的。72*72/210*703 (6英尺高,15英石)约为17,000。你需要体重除以身高的平方。
https://stackoverflow.com/questions/38361045
复制相似问题