19 | BMI Calculator |
You’ll often need to see if one value is within a certain range and alter the flow of a program as a result.
Create a program to calculate the body mass index (BMI) for a person using the person’s height in inches and weight in pounds. The program should prompt the user for weight and height.
Calculate the BMI by using the following formula:
If the BMI is between 18.5 and 25, display that the person is at a normal weight. If they are out of that range, tell them if they are underweight or overweight and tell them to consult their doctor.
Example Output
| Your BMI is 19.5. |
| You are within the ideal weight range. |
or
| Your BMI is 32.5. ... |
Get Exercises for Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.