【发布时间】:2019-04-04 18:21:57
【问题描述】:
我正在尝试让用户输入他们的信息,程序将获取这些信息并找到您的 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,它可能不应该是int。 -
现在您已经从
int.Parse切换到double.TryParse(来自您的上一个问题),如果解析失败,您的期望是什么?现在,它最终是0.0,但如果解析失败,你不应该测试它并让用户知道错误吗?换句话说,您更改了两件事(数据类型和解析模式),但只考虑了其中一件事的影响。 -
那么,您的问题在哪里?你有错误吗?出乎意料的结果?
-
@HimBromBeere 目前说 _bmiVal 不存在
-
好吧,你已经加倍了下划线
Console.WriteLine("Your BMI is" + __bmiVal + ...);。似乎只是一个错字。