bmi calculator...problem cannot matching else if

hi,right now my program to calculate bmi for male female ,athlete female and athlete male..i have have some problem,i don't know how to matching else if..can anyone help me...


#include<iostream>
#include<iomanip>
#include<math.h>
#include <cmath>


void Metre();
double cmi_b(double, double);
using namespace std;
int num[]= {25,30};
double number[]= {19.1, 25.8, 32.8, 37};

int main()

{

char gender;char athlete;


cout <<"Please enter your gender. M or F"<<endl;
cin>>gender;


if ((gender == 'F')||(gender =='f'))//cannot matching with else
cout <<"Are you athlete? Y or N"<<endl;
cin>>athlete;
{
if ((athlete == 'N')||(athlete =='n'))

{
float weight;
float height;
char response;
float bmi;

do
{
cout << "*****************************\n";
cout << "Please enter your weight (kg): ";
cin >> weight;
cout << "Please enter your height (m): ";
cin >> height;
bmi = weight/(height*height);
cout<<"\n";

cout<<"Your BMI is " << bmi << endl;

if (bmi < 18.5)
{
cout << "You are underweight!" << endl;
cout << "Eat more!!" << endl;
}
else if (bmi >= 18.5 && bmi <25)
{
cout << "You are normal!"<<endl;
cout << "You are cool!"<<endl;
}
else if (bmi >= 25 && bmi <30)
{
cout << "You are overweight!"<<endl;
cout << "You should diet!"<<endl;
}
else if (bmi >= 30)
{
cout << "You are obesity!"<<endl;
cout << "You should do more exercise!"<<endl;
}

else
cout << endl;

cout << "Would you like to enter the information again? ";
cin >> response;
}
while (toupper(response) == 'Y');
cout << "Okay, see you next time.." << endl;
return 0;
}

else if ((athlete =='Y')||(athlete =='y'))

{
float weight;
float height;
char response;
float bmi;

do
{
cout << "*****************************\n";
cout << "Please enter your weight (kg): ";
cin >> weight;
cout << "Please enter your height (m): ";
cin >> height;
bmi = weight/(height*height);
cout<<"\n";
cout<<"Your BMI is " << bmi << endl;

if (bmi < 19.1)
{
cout << "You are underweight!" << endl;
cout << "Eat more!!" << endl;
}
else if (bmi >= number[0] && bmi <num[0])
{
cout << "You are normal!"<<endl;
cout << "You are cool!"<<endl;
}
else if (bmi >= num[0] && bmi <num[1])
{
cout << "You are overweight!"<<endl;
cout << "You should diet!"<<endl;
}
else if (bmi >= num[1])
{
cout << "You are obesity!"<<endl;
cout << "You should do more exercise!"<<endl;
}

else
cout << endl;

cout << "Would you like to enter the information again? ";
cin >> response;
}
while (toupper(response) == 'Y');
cout << "Okay, see you next time.." << endl;
return 0;
}
}
else if ((gender =='M')||(gender == 'm'))//this else

{
Metre();
return 0;

}
else
return 0;
}

void Metre()
{
double height_m, weight_kg, cmi_a;
cout << "Please enter your height in metre :\n";
cin >> height_m;
cout << "Please enter your weight in kilograms :\n";
cin >> weight_kg;
cmi_a = cmi_b(weight_kg, height_m);
cout << "Your BMI is " << cmi_a << ".\n";
if (cmi_a <19.1)
{
cout << "You are underweight!" << endl;
cout << "Eat more!!" << endl;
}
else if (cmi_a >=19.1 && cmi_a <25.8)
{
cout << "You are normal!"<<endl;
cout << "You are cool!"<<endl;
}
else if (cmi_a >= 25.8 && cmi_a <32.2)
{
cout << "You are overweight!"<<endl;
cout << "You should diet!"<<endl;
}
else if (cmi_a >= 32.2)
{
cout << "You are obesity!"<<endl;
cout << "You should do more exercise!"<<endl;
}

else

cout << endl;
cout << "Thank you.\n";
}

double cmi_b (double w, double h)
{
double final_cmi;
final_cmi = (w /(h*h));
return final_cmi;
}

Ohk, just suggestions to start with:
1) Please use code tags. It makes the program easier to go through.
2) Please use indentation. I can't make out which loop of yours ends where, and I won't be surprised if you can't either..
3) Why not write a function/macro for the parts:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
if (cmi_a <19.1)
{
cout << "You are underweight!" << endl;
cout << "Eat more!!" << endl;
}
else if (cmi_a >=19.1 && cmi_a <25.8)
{
cout << "You are normal!"<<endl;
cout << "You are cool!"<<endl;
}
else if (cmi_a >= 25.8 && cmi_a <32.2)
{
cout << "You are overweight!"<<endl;
cout << "You should diet!"<<endl;
}
else if (cmi_a >= 32.2)
{
cout << "You are obesity!"<<endl;
cout << "You should do more exercise!"<<endl;
}


AND

1
2
3
4
5
6
cout << "Please enter your weight (kg): ";
cin >> weight;
cout << "Please enter your height (m): ";
cin >> height;
bmi = weight/(height*height);
cout<<"\n";


It'll make your code shorter, and again, easier to read and understand.

4) I think the line "You are obesity" is grammatically incorrect. It should be "You are obese". But that doesn't matter...

Correct these things, and I can help you out further.. :)
First (since I cannot write them again) please see http://www.cplusplus.com/forum/general/57960/
and then I hope I could help you.
Topic archived. No new replies allowed.