user10636563
user10636563

Reputation: 59

C# create an equation with Variables and If statement

I'm trying to have the user enter their information, and the program will take the info and find your BMI. I'm having trouble with my equation and if statement. I can't seem to find where my issue is.

 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");
  }

Upvotes: 0

Views: 475

Answers (1)

Ashkan Mobayen Khiabani
Ashkan Mobayen Khiabani

Reputation: 34152

_bmi should be a double not an int. change this line:

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

to

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

secondly as _bmi is a double, you don't need to Parse it, so remove this if and just keep its content:

if (double.TryParse(_bmi, out _bmiVal))

Upvotes: 1

Related Questions