| | |
If and elseif and else syntax
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2009
Posts: 38
Reputation:
Solved Threads: 0
Hello all,
I have to write a program that calculate a bmi of person whose weight is 170 pounds (it increases by 1 pound for each month for 12 months) and 70 inches, after I have all the bmi for each weight from 170 - 182 pounds, under each weight I need to indicate if his bmi is underweight, normal, overweight or obese. I have written the program using php script, but it does not seem to work correctly, could anyone shed some light on this. The program code is:
Thanks in advance,
Tony
I have to write a program that calculate a bmi of person whose weight is 170 pounds (it increases by 1 pound for each month for 12 months) and 70 inches, after I have all the bmi for each weight from 170 - 182 pounds, under each weight I need to indicate if his bmi is underweight, normal, overweight or obese. I have written the program using php script, but it does not seem to work correctly, could anyone shed some light on this. The program code is:
php Syntax (Toggle Plain Text)
<html> <head> <title>Lab 10a</title> </head> <body> <?php $pounds = 170; $inches = 70; $increase = 0; $poundsinch = 703; while ($increase < 13) { $division = ($pounds) / ($inches * $inches) * ($poundsinch); echo "The BMI of $pounds pounds and $inches inches is : ".$division."<br />"; echo " "; $increase = $increase + 1; $pounds = $pounds + 1; if ($division < 18.5) echo "You are underweight"; elseif ($division < 25){ echo "Your BMI is normal"; elseif ($division < 29.9) echo "You are overweight"; else{ echo "You are obese"; } ?> </body> </html>
Thanks in advance,
Tony
Last edited by peter_budo; Jul 10th, 2009 at 6:41 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Mar 2008
Posts: 152
Reputation:
Solved Threads: 19
I assume this is homework.
Part of learning to program is to put a bit more thought into things.
Not so good: It's not working. It doesnt work right. It's broke.
Good: I was expecting to see X and I see Y. What is the command to ____.
When you start to think this way, and post this way, your errors will sometimes become apparent to you, and you won't need as much help.
Part of learning to program is to put a bit more thought into things.
Not so good: It's not working. It doesnt work right. It's broke.
Good: I was expecting to see X and I see Y. What is the command to ____.
When you start to think this way, and post this way, your errors will sometimes become apparent to you, and you won't need as much help.
Last edited by kireol; Jul 8th, 2009 at 10:43 pm.
Why do Daniweb moderators edit CODE tags into CODE=style but don't check "solved".
Oh great. Now I have to google BMI and wade through corporate references or risk watching my intelligence decline.
Got it... BMI
Awful lot of science for something that within 15% is irrelevant.
Spending two seconds and only reading up to the first line of interest, the calculation of $DIVISION, I would start with looking up operator precedence in PHP and probably adding some parens.
Got it... BMI
Awful lot of science for something that within 15% is irrelevant.
Spending two seconds and only reading up to the first line of interest, the calculation of $DIVISION, I would start with looking up operator precedence in PHP and probably adding some parens.
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
To provide a useful answer:
- use [code] and [/code] tags around your code so it is displayed on the forum in a readable fashion
- use the "Preview Post" button to review your post before submitting it
- be sure your code is properly indented
- always use {} pairs around code blocks (while loops, if/else statements, etc.) even if there is only one statement in the block
- verify that the braces are properly paired.
•
•
Join Date: Jan 2008
Posts: 16
Reputation:
Solved Threads: 0
As was stated above, the clearer the question, ther clearer that answer. However, thought I'd help the lad/ladette out....
php Syntax (Toggle Plain Text)
<?php $pounds = 170; $inches = 70; $increase = 0; $poundsinch = 703; while ($increase < 13){ $division = number_format(($pounds) / ($inches * $inches) * ($poundsinch),2); echo "The BMI of $pounds pounds and $inches inches is : ".$division." "; if ($division < 18.5){ echo "You are underweight.<br />"; } elseif ($division < 25){ echo "Your BMI is normal.<br />"; } elseif ($division < 29.9){ echo "You are overweight.<br />"; } else{ echo "You are obese.<br />"; } $increase++; $pounds++; } ?>
![]() |
Similar Threads
- Parse error: syntax error, unexpected $end (PHP)
- syntax error, unexpected $end (PHP)
- Shopping Cart Not Working (ASP.NET)
- Help Needed Parse error: syntax error (PHP)
- MySQL syntax error check for the right syntax to use near 'A (A) )' at line 1 (PHP)
- Php Syntax Error (PHP)
- Parse error, syntax error, Forbids declaration (C++)
- Syntax for deleting specified file ( in C++) (C++)
- C++ Syntax (C++)
Other Threads in the PHP Forum
- Previous Thread: Checking for database updates
- Next Thread: Getting Php Message Fail Error..........`
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dropdown dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube





