//declare a variable called gender that can hold bool
bool gender;
//declare a variable called age, weight, and height that can hold large decimals
float weight, height;
//declare a variable called num that can hold whole numbers
int num, age;
//declare a variable called bmr
double bmr;
//prompt the user to "Enter 10 if male or enter 9 if female:" and a endline
cout << "Enter 10 if male or enter 9 if female:" << endl;
//wait for input and store it in num
cin >> num;
//check to see if num is equal to 10
if (num == 10){
//user is a male
gender = true;
}elseif (num == 9){
//user is female
gender = false;
}
//prompt the user to "Enter your age:" and a endline
cout << "Enter your age:" << endl;
//wait for input and store in age
cin >> age;
//prompt the user to "Enter your weight:" and a endline
cout << "Enter your weight:" << endl;
//wait for input and store in weight
cin >> weight;
//prompt the user to "Enter your height:" and a endline
cout << "Enter your height:" << endl;
//wait for input and store in height
cin >> height;
//calculate the bmr
if (gender == 10){
bmr = 66.5 + (13.8*weight) + (5.0*height) - (6.8*age);
}
if (gender == 9){
bmr = 655.1 + (9.6*weight) + (1.8*height) - (4.7*age);
}
//print "Your BMR is:" and print the user bmr on screen
cout << "Your BMR is:" << bmr << endl;
Yeah you should make sure when you declare any variables to initialize them.
Instead of double bmr; , you should initialize the value double bmr = 0; Not initializing values for variables upon declaration can have very bad consequences. Unless you're using large arrays and performance is an issue, it's probably a good idea to do always initialize your variables.
I put that in the beginning. I have to put it up again when I'm calculating it? so it will be if(gender == 9){
gender = false;
bmr = 655.1 + (9.6*weight) + (1.8*height) - (4.7*age);
Gender is a bool. A bool can hold only two values, true OR false (1 OR 0). It cannot and will not ever be 9 or 10. You must check for if(gender == true) and if(gender == false) appropriately, according to your code here:
1 2 3 4 5 6 7
//check to see if num is equal to 10
if (num == 10){
//user is a male
gender = true;
}elseif (num == 9){
//user is female
gender = false;
No, what you did is not correct. Please read my posts carefully.
No.
Gender is a bool. A bool can hold only two values, true OR false (1 OR 0). It cannot and will not ever be 9 or 10. You must check for if(gender == true) and if(gender == false)
//declare a variable called gender that can hold bool
bool gender;
//declare a variable called age, weight, and height that can hold large decimals
float weight, height;
//declare a variable called num that can hold whole numbers
int num, age;
//declare a variable called bmr
double bmr = 0;
//prompt the user to "Enter 10 if male or enter 9 if female:" and a endline
cout << "Enter 1 if male or enter 0 if female:" << endl;
//wait for input and store it in num
cin >> num;
//check to see if num is equal to 10
if (num == 1){
//user is a male
gender = true;
}elseif (num == 0){
//user is female
gender = false;
}
//prompt the user to "Enter your age:" and a endline
cout << "Enter your age:" << endl;
//wait for input and store in age
cin >> age;
//prompt the user to "Enter your weight:" and a endline
cout << "Enter your weight:" << endl;
//wait for input and store in weight
cin >> weight;
//prompt the user to "Enter your height:" and a endline
cout << "Enter your height:" << endl;
//wait for input and store in height
cin >> height;
//calculate the bmr
if (gender == 1){
bmr = 66.5 + (13.8*weight) + (5.0*height) - (6.8*age);
}
if (gender == 0){
bmr = 655.1 + (9.6*weight) + (1.8*height) - (4.7*age);
}