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.
#include <iostream>
#include <string>
usingnamespace 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);
}
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.
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!
#include <iostream>
#include <string>
usingnamespace 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;
}
}
elseif (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);
}