Jump to content

[SOLVED] Few probs with BMI calculator


darkfreaks

Recommended Posts

ok when your first see it it says division by zero on line 14

 

 

which is

 

 

<?php  $total=$weight/$heightwo *703; ?>

 

 

also when it divides i get something like  "Your  Body Mass Index is 9097.64705882%"

 

i want to format the number so the dot is the second digit to the left like  00.00%

Link to comment
https://forums.phpfreaks.com/topic/70840-solved-few-probs-with-bmi-calculator/
Share on other sites

my entire code is below i want it to calculate Body Mass Index Formula if someone can look one up and see if i have done my math correctly?

 


<?php 

$height= trim($_POST['height']);

$weight=trim($_POST['weight']);
$height=str_replace(',','',$height);
$height=str_replace('.','',$height);
$height=strip_tags($height);
$weight=strip_tags($weight);
$weight=str_replace(',','',$weight);
$weight=str_replace('.','',$weight);






if ($_POST['height']||$_POST['weight']=="true") 
{ 
$weighttwo=$weight*100;	

$total=$weighttwo/$height;}




if($_POST['weight']=="") {$error['weight']="Please enter a weight!";} else {unset($error['weight']);} 

if($_POST['height']=="") {$error['height']="Please enter a height!";} else {unset($error['height']);} 


if($error) {?>

<form method="POST">

<b>Height(inches):</b><input name="height" type="text" size="3"><?php if ($_POST) { echo $error['height'];} ?><b>Weight(lbs.):</b><input name="weight" type="text" size="3"><?php if ($_POST) { echo $error['weight'];} ?>
<input type="submit" name="Calculate!" value="Calculate!">

</form>

<?php } else{echo "Your Mass Body Index is"; echo $total; echo "%"; 


} ?>







ok so i put $bmi= ($weight*703)/($height*2);

 

and now its getting abit morre realistic i get  your BMi is 1083%

 

i want to knock it down to a 2 digit whole  so its like

 

1-50 percent

 

and even then i dont think its adding up right or something because it would be 10.83 percent and at my current weight and height it should come out to 29.9 percent

 

 

ok so i put $bmi= ($weight*703)/($height*2);

 

and now its getting abit morre realistic i get  your BMi is 1083%

 

i want to knock it down to a 2 digit whole  so its like

 

1-50 percent

 

and even then i dont think its adding up right or something because it would be 10.83 percent and at my current weight and height it should come out to 29.9 percent

 

 

 

If you'll notice, AndyB didn't say "height * 2", he said "height * height". There's a rather significant difference there.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.