### BMI program

i need help with this program. i have tried applying the formula that was given to me into the code but when i try use the (pow) function an error comes out.

Write a program that calculates and displays a person s body mass index (BMI). The
BMI is often used to determine whether a person with a sedentary lifestyle is overweight
or underweight for his or her height. A person s BMI is calculated with the following
formula:
BMI = weight × 703 / height2
where weight is measured in pounds and height is measured in inches. The program
should display a message indicating whether the person has optimal weight, is underweight,
or is overweight. A sedentary person s weight is considered to be optimal if his
or her BMI is between 18.5 and 25. If the BMI is less than 18.5, the person is considered
to be underweight. If the BMI value is greater than 25, the person is considered
to be overweight.

 ``123456789`` `````` this is all have done so far.. int weight, height, BMI; cout << "what is your weight and height? put a space in between answers." << endl; cin >> weight >> height; BMI = (weight * 703)/pow(height, 2);``````
Did you #include <cmath>?
yeah..
What's the error then?
`pow(height, 2)` Both height and 3 are integers.

Problem
The pow() function is overloaded, that is to say, there are several different versions, each taking a different type of parameter, such as `double`, `float` or `long double`. Normally the compiler selects the appropriate version based upon the types of the supplied parameters. Unfortunately, two integer parameters is not one of the options so the compiler is unable to resolve the ambiguity.

Solution
Usually it is sufficient to make sure that at least one parameter is of type float or double. For example `pow(height, 2.0)` should work as 2.0 is of type `double`.
http://www.cplusplus.com/reference/cmath/pow/

Last edited on
thank you chervil! i was wondering why it wasnt working but now there is another problem when i compiled it. i put in the weight in pounds and height in inches. the thing is it just says " run succesful " and doesnt display whether the user is overweight or underweight..
Blank, you need to put in a few if - else if statements to handle the different outcomes. (Or use switch statements if you prefer.)

This code works for me:

 ``1234567891011121314151617181920212223242526`` ``````#include using namespace std; int main() { int weight; float height,BMI; cout<<"Please enter your weight in pounds: "; cin>>weight; cout<<"\nPlease enter your height in inches: "; cin>>height; BMI =weight*703/(height*height); cout<<"\nYour body mass Index is: "<25) cout<<"\n\nYou are somewhat overweight."; else if (BMI<18.5) cout<<"\n\nYou are somewhat underweight."; else if (BMI>18.5 && BMI <25) cout<<"\n\nCongratulations! You are within a healthy weight range."; cin.get (); cin.get (); return 0; }``````

As you can see, without the pow() function there is no need to include cmath, although I like it and often use it!
Donnie.
thank yoiu donnie! i appreciate the tips and how to improve the code!. thank you for all the help everybody i would of been lost without the feedback!
Topic archived. No new replies allowed.