我试图让用户输入他们的信息,该程序将获取该信息并找到您的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");
}
答案 0 :(得分:1)
_bmi应该是double
而不是int
。更改此行:
int _bmi = (_poundsVal / (_inchesVal * _heightVal)) * 703;
到
double _bmi = (_poundsVal / (_inchesVal * _heightVal)) * 703;
其次,因为_bmi是双精度型,因此您无需解析它,因此如果保留并保留其内容,则将其删除:
if (double.TryParse(_bmi, out _bmiVal))