logo CodeStepByStep logo

bmi

Language/Type: PHP interactive programs parameters

Write a console program that prompts for user input and calculates two people's body mass index (BMI), using the following formula:

BMI = weight / height2 * 703

The BMI rating groups each person into one of the following four categories:

BMI Category
below 18.5 class 1
18.5 - 24.9 class 2
25.0 - 29.9 class 3
30.0 and up class 4

Match the following example output:

This program reads data for two people
and computes their body mass index (BMI).

Person 1's information:
height (in inches)? 70.0
weight (in pounds)? 194.25
BMI = 27.9
class 3

Person 2's information:
height (in inches)? 62.5
weight (in pounds)? 130.5
BMI = 23.5
class 2

Have a nice day!

You should break down your program into several functions, each of which helps solve the overall problem. Your function bmi is the main function that will be called however. Use the number_format($num, $precision) function to format a $num with $precision decimal places of precision.

Bare code: Write a fragment of PHP code as described, without any class or function/method heading around your code.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.