我正在尝试让用户输入他们的信息,程序将获取信息并找到您的BMI。我的等式和if语句都有问题。我似乎无法找到我的问题所在。
double _bmi = (_poundsVal / (_inchesVal * _heightVal)) * 703;
if (_bmi <= 18.5)
{
Console.WriteLine("Your BMI is" + _bmi.ToString() + "you are considered underweight");
}
else if (_bmi > 18.5 && _bmi <= 24.9)
{
Console.WriteLine("Your BMI is " + _bmi.ToString() + "you are considered normal weight");
}
else if (_bmi <= 25 && _bmi <= 29.9)
{
Console.WriteLine("Your BMI is" + _bmi.ToString() + "you are considered overweight");
}
else
{
Console.WriteLine("Your BMI is" + _bmi.ToString() + "you are considered obese");
}
_bmi应该是double
而不是int
。改变这一行:
int _bmi = (_poundsVal / (_inchesVal * _heightVal)) * 703;
至
double _bmi = (_poundsVal / (_inchesVal * _heightVal)) * 703;
其次,因为_bmi是双精度数,所以你不需要解析它,所以如果只是保留其内容,请删除它:
if (double.TryParse(_bmi, out _bmiVal))