在我最近的項目中,簡而言之,我正在計算BMI。C++ - 意外BMI計算
我使用的重量和高度(double類型)一維陣列
爲了計算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;
}
請縮進您的代碼。刷新到左邊界的所有內容都很難閱讀。另外,爲什麼'#包括'? –
PaulMcKenzie
*會返回BMI計算的結果是問題的根源嗎?* - 您應該首先使用已知數據測試您的功能。如果它在單元測試時正常工作,那麼功能不是問題。 – PaulMcKenzie
注意事項。有了您的問題,,它很容易用於個人視覺表示(SetConsoleTitle)。 –