Calculation error

Sep 18, 2013 at 8:12pm
after I put in all my numbers and the result is displayed I get a huge or tiny number. Not sure what the problem is.

#include <iostream>
using namespace std;
int main()
{
//Declare Variables
int height, age;
double weight, bmr;
char gender;

//Input
cout<< "Enter your weight in pounds\n";
cin>> weight;
cout<< "Enter your height in inches\n";
cin>> height;
cout<< "Enter your age in years\n";
cin>> age;
cout<< "Enter male or female\n";
cin>> gender;


if (gender == 'male')
{
66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
}
else
{
655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);
}

cout<< "Your bmr is"<< bmr << "calories\n";

}
Sep 18, 2013 at 8:16pm
What did you store in bmr?
It looks like you are getting what ever was at the memory location when bmr was initialized.
Sep 18, 2013 at 8:16pm
closed account (jwkNwA7f)
In these places, you are not assigning bmr a value:
66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);

655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);

EDIT: You are also mixing data types: doubles and ints. And, gender will only accept one character.

You should define gender like this: char *gender;, and then,
use ""'s instead of '''s in the if and else statements.
Last edited on Sep 18, 2013 at 8:20pm
Sep 18, 2013 at 8:23pm
char gender can store only one character but you are checking that if it is equal to "male" i.e they are four characters.

66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
you are niether assigning it to any variable nor using it in any other way.better assign to some variable to use it.
Sep 18, 2013 at 8:30pm
All that stuff worked! thanks guys!
Topic archived. No new replies allowed.