I'm trying to make a BMI calculator...so far, I have everything displaying properly, except for the actual BMI range (below, normal, above).
There's most likely an issue with my if/elseif statements, because the output is always wrong. Here's my code:
<?php
$weight = $_POST['txtWeight'];
$height = $_POST['txtHeight'];
$selected_unit = $_POST['optUnit'];
$metric_status = 'unchecked';
$imperial_status = 'unchecked';
$impCalc = ($weight * 703) / ($height * $height);
$metCalc = $weight / ($height * $height);
$below = 'below average.';
$normal = 'normal.';
$above = 'above average.';
if (($impCalc < 18.5) || ($metCalc < 18.5))
{
$bmi = $below;
}
elseif (($impCalc >= 18.5 && $impCalc <= 24.9) || ($metCalc >= 18.5 || $metCalc <= 24.9))
{
$bmi = $normal;
}
else
{
$bmi = $above;
}
if (isset($_POST['btnEnter']))
{
$selected_unit = $_POST['optUnit'];
if($selected_unit == 'imperial')
{
$imperial_status = 'checked';
echo "A height of {$height} inches and a weight of {$weight} pounds = {$impCalc} BMI. Your BMI calc is: {$bmi}";
}
else if($selected_unit =='metric')
{
$metric_status = 'checked';
echo "A height of {$height} meters and a weight of {$weight} kilograms: {$metCalc} BMI. Your BMI calc is: {$bmi}";
}
}
?>
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire