Jump to content

Recommended Posts

okay so everything should work it echos right for underweight and normal weight but if i go over 30 percent it echos you are normal weight. when it should echo you are obese please consort a doctor.

 

 

 



<?php } else if ($total<18.50){	
echo "Your Body Mass Index is"; printf ('%01.2f',$total); echo "%"; echo "<b>You are Currently Underweight This is not healthy</b>";}
else if ($total>18.50){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";}

else if ($total<25){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";}

else if ($total>25){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis!</b>";}

else if ($total<30){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis!</b>";}

else if ($total>30){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis! Consult a Doctor ASAP!</b>";}
?>



 

Link to comment
https://forums.phpfreaks.com/topic/71219-else-if-problems/
Share on other sites

Well if your $total is 100 the first condition thats going to be met is that $total is > than 18.5. The other conditions wont get a look in. You want your conditions to be greater than a and less than b. Also doing this as a switch{} would be a bit cleaner.

Link to comment
https://forums.phpfreaks.com/topic/71219-else-if-problems/#findComment-358225
Share on other sites

Your problem is a math error.

Say you run the number 100 through the statements. it will run through the first 2 but on the 3rd (>25) it returns true. So if the number is over 25 AND 30 it will run through the first one on the list.

You would need to add a domain such as 25<x<30 (number is greater than 25 but less than 30) then x<30

<?php } else if ($total<18.50){	
echo "Your Body Mass Index is"; printf ('%01.2f',$total); echo "%"; echo "<b>You are Currently Underweight This is not healthy</b>";}
else if ($total>18.50 && $total<25){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";}

else if ($total<25){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";}

else if ($total>25 && $total<30){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis!</b>";}

else if ($total<30){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis!</b>";}

else if ($total>30){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis! Consult a Doctor ASAP!</b>";}
?>

I hope that works and makes sense

Link to comment
https://forums.phpfreaks.com/topic/71219-else-if-problems/#findComment-358230
Share on other sites

my current code is

 



<?php } else if ($total<18.50){	
echo "Your Body Mass Index is"; printf ('%01.2f',$total); echo "%"; echo "<b>You are Currently Underweight This is not healthy</b>";}
else if ($total>18.50){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";}

else if ($total<25||$total>25){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";}

else if ($total<30){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis!</b>";}

else if ($total>30){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis! Consult a Doctor ASAP!</b>";}
?>


Link to comment
https://forums.phpfreaks.com/topic/71219-else-if-problems/#findComment-358240
Share on other sites

okay so i fixed up the code using switch but im getting erros can someone fix them plz?

 

<?php

switch ($total) {

case $total>18.50:

    echo "Your Body Mass Index is"; printf ('%01.2f',$total);

echo "%"; echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";

    break;

case $total<18.50:

    echo "Your Body Mass Index is"; printf ('%01.2f',$total); echo "%"; echo "<b>You are Currently Underweight This is not healthy</b>";

    break;

case $total<25:

    echo Your Body Mass Index is"; printf ('%01.2f',$total);

echo "%"; echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";

    break;

 

case $total>25:

echo "Your Body Mass Index is"; printf ('%01.2f',$total);

echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis!</b>";

break;

case $total>30:

echo "Your Body Mass Index is"; printf ('%01.2f',$total);

echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis! Consult a Doctor ASAP!</b>";

break;

?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/71219-else-if-problems/#findComment-358248
Share on other sites


<?php
switch ($total) {
case $total>18.50:
    echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "You are Normal Weight, give yourself a pat on the back!";
    break;
case $total<18.50:
    echo "Your Body Mass Index is"; printf ('%01.2f',$total); echo "%"; echo "You are Currently Underweight This is not healthy";
    break;
case $total<25:
    echo Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "You are Normal Weight, give yourself a pat on the back!";
    break;

case $total>25:
echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "You are Over Weight, Get to Exercizing on a Daily Basis!";
break;
case $total>30:
echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "You are Over Weight, Get to Exercizing on a Daily Basis! Consult a Doctor ASAP!";
break;
}
?>

Try that, if not paste your EXACT errors.

Link to comment
https://forums.phpfreaks.com/topic/71219-else-if-problems/#findComment-358255
Share on other sites

Your Body Mass Index is0.00%You are Normal Weight, give yourself a pat on the back!

 

need to know how to make that stop echoing if nothing is filled in.

 

also shouldt it be saying you are under weight since it equals nothing?

go herehttp://www.w3schools.com/php/php_switch.asp it will show you how to use the default action in the switch statement and explain it.

 

Link to comment
https://forums.phpfreaks.com/topic/71219-else-if-problems/#findComment-358265
Share on other sites

okay set the default value so it doesnt echo at all.

 

but now im still getting  your BMI is 29.9 percent your a normal weight when its sposed to echo your overweight please exercise should i get rid of the if else statements and leave the switch part?

Link to comment
https://forums.phpfreaks.com/topic/71219-else-if-problems/#findComment-358271
Share on other sites

yeah i noticed it appeared blank so i put it back perhaps my statements are more flawed than i originally thought?

 

<?php

} else if ($total<18.50){	
echo "Your Body Mass Index is"; printf ('%01.2f',$total); echo "%"; echo "<b>You are Currently Underweight This is not healthy</b>";}
else if ($total>18.50){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";}

else if ($total<25){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";}
else if ($total>25){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis!</b>";}

else if ($total<30){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis!</b>";}

else if ($total>30){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis! Consult a Doctor ASAP!</b>";}


switch ($total) {

case $total=0:
    break;

case $total>18.50:
    echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "You are Normal Weight, give yourself a pat on the back!";
    break;
case $total<18.50:
    echo "Your Body Mass Index is"; printf ('%01.2f',$total); echo "%"; echo "You are Currently Underweight This is not healthy";
    break;
case $total<25:
    echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "You are Normal Weight, give yourself a pat on the back!";
    break;

case $total>25:
echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "You are Over Weight, Get to Exercizing on a Daily Basis!";
break;
case $total>30:
echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "You are Over Weight, Get to Exercizing on a Daily Basis! Consult a Doctor ASAP!";
break;
}



?>

Link to comment
https://forums.phpfreaks.com/topic/71219-else-if-problems/#findComment-358276
Share on other sites

<?php 
if(i dont know where to start condition)//just put here yours
} 
else if ($total<18.50){	
echo "Your Body Mass Index is"; 
printf ('%01.2f',$total);
	echo "%";
	echo "<b>You are Currently Underweight This is not healthy</b>";
}
else if ($total<25){
echo "Your Body Mass Index is"; 
printf ('%01.2f',$total);
echo "%"; 	
echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";
}

else if ($total<30){
echo "Your Body Mass Index is"; 
printf ('%01.2f',$total);
echo "%"; 
echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";
}



else{
echo "Your Body Mass Index is"; 
printf ('%01.2f',$total);
echo "%"; 
echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis! Consult a Doctor ASAP!</b>";
}
?>



Link to comment
https://forums.phpfreaks.com/topic/71219-else-if-problems/#findComment-358279
Share on other sites

ok my problem is  the following statement wont work i have 5 if else statements that work if i change them to if and if else statements it echos everything upon submit instead of doing the math and figuring otu what to echo.

 

 

the last 4 statements that dont work right:

 

<?php

else if ($total<25){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Normal Weight, give yourself a pat on the back!</b>";}
else if ($total>25){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis!</b>";}

else if ($total<30){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis!</b>";}

else if ($total>30){echo "Your Body Mass Index is"; printf ('%01.2f',$total);
echo "%"; echo "<b>You are Over Weight, Get to Exercizing on a Daily Basis! Consult a Doctor ASAP!</b>";}?>


Link to comment
https://forums.phpfreaks.com/topic/71219-else-if-problems/#findComment-358513
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.