15,506,025 members
See more:
can someone help me to get the right answer when radio button metric is checked i get the write bmr from height (cm )and weight (kg) but when imperial US button is checked i am not able to get the right answer, For the Imperial option , given in feet (ft) and inches (in) and weight is in pounds (lb).

note : BMR = 10 * weight (kg) + 6.25 * height (cm) - 5 * age (y I tried this code but did not work for me

any help would be appreciated Thanks in advance
i know my code is a mess but i am just a beginner

What I have tried:

C#
```private bool InputBMR()
{
{
if (BmrCalc.GetUnit() == UnitTypes.Us)
if
(int.TryParse(txtAge.Text, out var age) &&
double.TryParse(txtHeightInch.Text, out var height) &&
double.TryParse(txtWeight.Text, out var weight))
{
double num1, num2, result;
num1 = Convert.ToDouble(txtheightIFeet.Text);
num2 = Convert.ToDouble(txtHeightInch.Text);
result = (num2 + (num1 * 12));
BmrCalc.Age = age;
BmrCalc.Height = result;
BmrCalc.Weight = weight;
return true;
}
else
{
MessageBox.Show("Error: Invalid input in bmr calculator. ", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
if(rdoMetric.Checked)
if(int.TryParse(txtAge.Text, out var age) &&
double.TryParse(txtHeightInch.Text, out var height) &&
double.TryParse(txtWeight.Text, out var weight))
{
BmrCalc.Age = age;
BmrCalc.Height = height;
BmrCalc.Weight = weight;
return true;
}
else
{
MessageBox.Show("Error: Invalid input in Bmi calculator. Height must be numbers ", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return true;
}```
Posted
Updated 16-Feb-21 2:45am
v2

## Solution 1

Quote:
double num1, num2, result;
num1 = Convert.ToDouble(txtheightIFeet.Text);
num2 = Convert.ToDouble(txtHeightInch.Text);
result = (num2 + (num1 * 12));
BmrCalc.Age = age;
BmrCalc.Height = result;
BmrCalc.Weight = weight;
return true;

In the above code you should have converted the values from imperial to metric units.
That is
C#
```BmrCalc.Age = age;
BmrCalc.Height = (num1 * 12 + num2) * 2.54; // height in cm
BmrCalc.Weight = weight * 0.453592; // weight in kg
```

Maciej Los 16-Feb-21 8:10am
5ed!
CPallini 16-Feb-21 9:14am
Thank you!
Rash Abs 16-Feb-21 8:20am
THANKS CPallini
CPallini 16-Feb-21 9:14am
You are welcome.