If Else statement

I am having more problems with the if else statement.. it does not seem to using the right equations...



#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 m or f\n";
cin>> gender;

if (gender == 'm') || (gender == 'f');

bmr = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);

else

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


cout<< "Your bmr is" << bmr << "calories"<<endl;
cout<< "Number of chocalate bars is equal to"<< (bmr/230)<<endl;

}
closed account (jwkNwA7f)
Here, there is a period at the end that shouldn't be there, and there are two ()'s:
if (gender == 'm') || (gender == 'f');
It should be:
if (gender == 'm' || gender == 'f')

And then, you are still mixing double's and int's.
You seem to have
1
2
3
4
if ( condition ) statement ;
// where
// condition: gender == 'm'
// statement: || (gender == 'f') 

Try
1
2
3
4
5
6
7
8
9
10
if ( condition )
{
  // statements
}
else
{
  // statements
}
// where
// condition: (gender == 'm') || (gender == 'f') 
Do you mean this:

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

because its still not switching between formula
closed account (jwkNwA7f)
Yes.
Not sure what the problem is then
No. That code doesn't even compile, so it can't give any results, good or bad.
This compiles and runs but it still only gives one solution for both male and female.?



include <iostream>
using namespace std;
int main()
{
//Declare Variables
int height;
int age;
double weight;
double 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 m or f\n";
cin>> gender;

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

cout<< "Your bmr is" << bmr << "calories"<<endl;
cout<< "Number of chocalate bars is equal to"<< (bmr/230)<<endl;

}
closed account (jwkNwA7f)
Ahh, Here:
if (gender = 'm')
Should be:
if (gender == 'm')
I literally did that just before you wrote this and it worked!!! So happy! Thanks for the help
Topic archived. No new replies allowed.