Where is this program wrong?

I have to create a program to determine the number of calories to intake daily to maintain weight, based on gender, activity, and weight.My program runs when I say i'm a Male, but if i say i'm a female, the program will run its calculations correctly and then reask to input if your inactive or active. why is it doing this, I couldn't figure it out, Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

#include <iostream>
#include <string>
using namespace std;

int main ()

{	
	// Declaring Variables
    float Calories = 0.0;
    float Weight = 0.0;
    string Gender, Activity;
    
    
    //enter gender
    cout<<"Please Enter Gender (M/F):";
    cin>> Gender;
    

    
    //Determining if the gender is a male or female.
	// Once gender is declared, determining if person is active or inactive.
	// Performing calculations depending on differnt criteria.

     if (Gender == "F")
	 {
     cout << "Enter Your Activity Level (Active/Inactive):";
     cin >> Activity;
	 
	
               if  (Activity == "Active")
			   {    
				   cout << "Enter Current Weight: ";
                       cin >> Weight;

                       Calories = Weight * 12;

                       cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight: " << Calories <<endl;
               }
               
               
               else    (Activity == "Inactive");
			   {
                       cout << "Enter Current Weight:  ";
                       cin >> Weight;

                       Calories = Weight * 10;

                       cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight: " << Calories <<endl;
               }
			   
}
    
    
	 else  (Gender == "M");           
	{
               cout << "Enter Your Activity Level (Active/Inactive): ";
               cin >> Activity;
               
	}
               
               if       (Activity == "Active")
			   {     
				   cout << "Enter Current Weight: ";
                        cin >> Weight;
                        
						Calories = Weight * 15;
                        
						cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight: " << Calories <<endl;
                        }
               
               
               else     (Activity == "Inactive");
			   {
                        cout << "Enter Current Weight:  ";
                        cin >> Weight;

                        Calories = Weight * 13;

                        cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight:  " << Calories <<endl;
			   }
     

	}

	return (0);
}
Last edited on
First off if you want to check the value of Activity in your "else" portion of the statement it should be "else if". Second, remove the semicolon from the end of any if/else line (73, 55, 42).

After that, the else statement on line 55 only encompasses lines 56 through 60 when I believe you intend for it to enclose the whole second half.
return (0); should be return 0;
@leftcoast
return (0); should be return 0;


It is interesting why should return ( 0 ); be return 0; ?
You're right viad. It should not matter. I thought that I had some problems when I ran the program yesterday. No problem with running the program this morning. Thanks for the correction!
i removed the semicolons on the lines you reccomended. Now line 45 and 76 is getting a syntax error....

error C2143: syntax error : missing ';' before '{' 45
error C2143: syntax error : missing ';' before '{' 76

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <string>
using namespace std;

int main ()

{	
	// Declaring Variables
    float Calories = 0.0;
    float Weight = 0.0;
    string Gender, Activity;
    
    
    //enter gender
    cout<<"Please Enter Gender (M/F):";
    cin>> Gender;
    

    
    //Determining if the gender is a male or female.
	// Once gender is declared, determining if person is active or inactive.
	// Performing calculations depending on differnt criteria.

     if (Gender == "F")
	 {
     cout << "Enter Your Activity Level (Active/Inactive):";
     cin >> Activity;
	 
	
               if  (Activity == "Active")
			   {    
				   cout << "Enter Current Weight: ";
                       cin >> Weight;

                       Calories = Weight * 12;

                       cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight: " << Calories <<endl;
               }
               
               
               else    (Activity == "Inactive")
			   {
                       cout << "Enter Current Weight:  ";
                       cin >> Weight;

                       Calories = Weight * 10;

                       cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight: " << Calories <<endl;
               }
			   
}
    
    
	 else  if (Gender == "M")       
	{
               cout << "Enter Your Activity Level (Active/Inactive): ";
               cin >> Activity;
               
	
               
               if       (Activity == "Active")
			   {     
				   cout << "Enter Current Weight: ";
                        cin >> Weight;
                        
						Calories = Weight * 15;
                        
						cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight: " << Calories <<endl;
                        }
               
               
               else     (Activity == "Inactive")
			   {
                        cout << "Enter Current Weight:  ";
                        cin >> Weight;

                        Calories = Weight * 13;

                        cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight:  " << Calories <<endl;
			   }
     

	}

	return (0);
	

}
On lines 41 & 72, the else statements need a ; at the end to complete the statements.
ty
Topic archived. No new replies allowed.