C#使用Variables和If语句创建一个等式

问题描述 投票:0回答:1

我正在尝试让用户输入他们的信息,程序将获取信息并找到您的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");
  }
c# equation
1个回答
1
投票

_bmi应该是double而不是int。改变这一行:

int _bmi = (_poundsVal / (_inchesVal * _heightVal)) * 703;

double _bmi = (_poundsVal / (_inchesVal * _heightVal)) * 703;

其次,因为_bmi是双精度数,所以你不需要解析它,所以如果只是保留其内容,请删除它:

if (double.TryParse(_bmi, out _bmiVal))
© www.soinside.com 2019 - 2024. All rights reserved.