### 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.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687`` `````` #include #include 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 <> Weight; Calories = Weight * 10; cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight: " << Calories <> 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 <> Weight; Calories = Weight * 13; cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight: " << Calories <
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

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788`` ``````#include #include 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 <> Weight; Calories = Weight * 10; cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight: " << Calories <> 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 <> Weight; Calories = Weight * 13; cout << "You Need To Intake this Many Calories Daily To Maintain Your Weight: " << Calories <
On lines 41 & 72, the else statements need a ; at the end to complete the statements.
ty
Topic archived. No new replies allowed.