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
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 "%"; 


} ?>







Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Link to comment
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.