0
저는 많은 사람들의 평균 BMI를 계산하려고합니다. 이 코드를 실행하면 계산 버튼을 클릭 할 때마다 평균 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;
당신은 루프에서이 일을하고 있는가? 변수를 다시 사용하기 전에 변수 값을 다시 0으로 재설정하지 않으면 값이 누적됩니다. –