Nested if else statement errors

I've never posted in a forum before. I wish I could highlight my "else" errors I'm getting. Does anyone see anything wrong with this code pertaining to if/else statements? It's maddening. I'm getting four errors on my "else's".
It's the four that are in the two separate functions (each one starts with "else if", then has another else after it). It's for class, and it's a program to calculate the calories a male/female needs to maintain their current weight (with an activity level and weight). Please and thank you

//IV. Code the algorithm into a Program
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
//declare variables and named constants
char gender = ' ';
char level = ' ';
double weight = 0.0;
double dcn = 0.0;

//enter input items
cout << "Enter gender to determine how many calories are needed to maintain your current weight (M or F): ";
cin >> gender;
gender = toupper(gender);

// selection
if (gender == 'F')
{
cout << "Enter activity level (A or I): ";
cin >> level;
level = toupper(level);
// nested selection
if (level == 'I')
cout << "Enter weight: ";
cin >> weight;
dcn = (weight*10);
cout << dcn << endl;
else if (level == 'A')
cout << "Enter weight: ";
cin >> weight;
dcn = (weight*12);
cout << dcn << endl;
else
cout << "Invalid selection: ";
}
else if (gender == 'M')
{
cout << "Enter activity level (A or I): ";
cin >> level;
level = toupper(level);
// nested selection
if (level == 'I')
cout << "Enter weight: ";
cin >> weight;
dcn = (weight*13);
cout << dcn << endl;
else if (level == 'A')
cout << "Enter weight: ";
cin >> weight;
dcn = (weight*15);
cout << dcn << endl;
else
cout << "Invalid selection: ";
}
else
cout << "Invalid selection: ";
//system("pause"); // use if needed
return 0;

} //end of main function
yes there seems to be two "else" statement.
try to use brackets "{}" to execute more that one line in "if" statement, that will help you find the problem.

for example from your code,
1
2
3
4
5
if (level == 'I')
   cout << "Enter weight: "; 
   cin >> weight;
   dcn = (weight*10);
   cout << dcn << endl;

when "level" is not equal to 'I', it wont run the cout << "Enter weight: " but still gonna run the cin >> weight; dcn = ...... statement.
Ok, thanks. I'll play around some more with it. Thanks for opening my eyes (again!) to thinking like a computer. I can't assume anything.
hye,some one please help me.why when i enter month=12,date =15,it doesnt display"available"?it suppose to print it .where i did mistakes?
i really need your help

#include<stdio.h>
int main()
{
int date,month,year;
printf("Please enter year:");
scanf("%d",&year);
printf("Please enter month:");
scanf("%d",&month);
printf("Please enter date:");
scanf("%d",&date);

if((month==1)&&(month==3)&&(month==12)){
if((date<10)&&(date>20)){
printf(" not available");
}

else{
printf("available");}

}
}


@diyzoe

Please start your own topic, don't hijack this one. Starting your own topic is easy. When you do put your code into code tags. Select your code, then press the <> button on the right under formatting.

If you don't do this, you might not get any replies, or worse you could be reported which would remove your post.
Topic archived. No new replies allowed.