我正在尝试计算一些人的平均 BMI。当我运行此代码时,每次单击计算按钮时,平均 BMI 都会下降。为什么?
float feet;
float inches;
float height;
float weight;
float bmi;
float averagebmi;
try
{
//Get user input.
feet = float.Parse(txtFeet.Text);
inches = float.Parse(txtInches.Text);
weight = float.Parse(txtWeight.Text);
//Calculations.
inches += feet * 12;
height = inches * (float)0.0254;
weight = weight * (float)0.453592;
bmi = weight / (height * height);
//Manager Calculations.
totalPeople += 1;
bmi += 1;
averagebmi = bmi / totalPeople;