Working on a program that calculates the users BMR and I ran into an error that I can't figure out how to fix. Before this error, I had an error I was getting in "function double increase_bmr (string activity_lvl, double sum1)" for the if statements that said that "sum1" was not declared, so I put "double sum1" into the function declaration and heading, as well as "sum1" in the function call, it fixed the "no sum1 declaration" but then I got this error:
/var/tmp//cc066PnW.o: In function `main':
proj3.cc: (.text+0x54c): undefined reference to `calculate_bmr(int, int, int, char)'
collect2: ld returned 1 exit status
I kinda understand what the error is trying to say, but I have no idea what I need to change to fix it, help?
CODE:
Code:
#include <iostream>
#include <string>
using namespace std;
double calculate_bmr (int weight, int height, int age, char sex);
double increase_bmr (string activity_lvl, double sum1);
int main()
{
double choc_bar; //number of chocolate bars the user can eat to maintain their weight
double bmr; //users BMR before taking into account the users activity level
double mod_bmr; //users BMR after taking into account the users activity level
double sum1; //returned value from function
int height; //users height in inches
int weight; //users weight in pounds
int age; //users age in years
char sex; //users sex male or female
char again; //determines if users wants data for another BMR or if they are done
string activity_lvl; //users activity level
string full_sex; //outputs the users sex in a full word male or female not just a character m or f
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2); //sets decimal space limit to 2 spaces
while (again == 'Y' || again == 'y')
{
cout << "Enter the height in inches --> ";
cin >> height;
cout << "Enter the weight in pounds --> ";
cin >> weight;
cout << "Enter the age --> ";
cin >> age;
cout << "Enter the sex (M for male and F for female) --> ";
cin >> sex;
while (sex != 'm' && sex != 'M' && sex != 'f' && sex != 'F') //will reprompt the user if an incalid sex is entered
{
cout << "Please enter a vaild sex (M for male and F for female) --> ";
cin >> sex;
} //end reprompt
if (sex == 'm' || sex == 'M')
full_sex = "Male";
else if (sex == 'f' || sex == 'F')
full_sex = "Female";
cout << "Enter the activity level"
<< endl << endl
<< "Sedentary Somewhat Active Highly --> ";
cin >> activity_lvl;
while (activity_lvl != "Sedentary" && activity_lvl != "sedentary" && //will reprompt the user if an invalid activity level is entered
activity_lvl != "Somewhat" && activity_lvl != "somewhat" &&
activity_lvl != "Active" && activity_lvl != "active" &&
activity_lvl != "Highly" && activity_lvl != "highly")
{
cout << "Please enter a valid activity level"
<< endl << endl
<< "Sedentary Somewhat Active Highly --> ";
cin >> activity_lvl;
} //end reprompt
bmr = calculate_bmr (weight, height, age, sex);
mod_bmr = increase_bmr (activity_lvl, sum1);
cout << "A " << full_sex << " with the weight "
<< weight << " pounds, height " << height
<< " inches " << age << " years of age and with "
<< activity_lvl << " activity level has a BMR of ";
cout << "Another y/n --> "; //determines whether or not the user wants to do another BMR calculation if not program ends
cin >> again;
return (0);
}
}
double caluclate_bmr (int weight, int height, int age, char sex) //calculate BMR
{
double sum1;
if (sex == 'M' || sex == 'm')
sum1 = 655 + (4.3 * weight) + (4.7 * height) - (6.8 * age);
else if (sex == 'F' || sex == 'f')
sum1 = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
return (sum1);
}
double increase_bmr (string activity_lvl, double sum1) //takes into account activity level and increases BMR
{
double sum2;
if (activity_lvl == "Sedentary" || activity_lvl == "sedentary")
sum2 = sum1 * 1.2;
else if (activity_lvl == "Somewhat" || activity_lvl == "somewhat")
sum2 = sum1 * 1.3;
else if (activity_lvl == "Active" || activity_lvl == "active")
sum2 = sum1 * 1.4;
else if (activity_lvl == "Highly" || activity_lvl == "highly")
sum2 = sum1 * 1.5;
return (sum2);
}