Function issues

Hi guys, I'm having problems with my code. I am trying to develop a code which gets the: weight, height, age, and gender from the user and in light of that information calculate their BMR and print the BMR on screen. I am having huge problems and out of options.

[code]
#include<iostream>
#include<string>

//Function Headers
using namespace std;
void greeting();
void getData (double& weight, double& age, double& height);
int getgender();
bool specified (int option);
void calcData (bool initiated, double& weight, double& age, double& height);
void printmessage (bool initiated);



//Main Fuction
int main(){

//Declare variables that can hold whole numbers.
int option;
//Declare varaibles that can hold decimal numbers
double weight, age, height;
//Declare a variable that can hold either true or false
bool initiated;

//Function Calls
greeting();
getData (weight, age, height);
getgender();
option = getgender();
specified (option);
initiated = false;
calcData (initiated, weight, age, height);
printmessage (initiated);


system ("pause");
return 0;
}

//This functions pupose serves an intrduction. Uses to adequetly specify the programs intent to the user.
void greeting(){
//print on screen, "Basal Metabolic Rate Calculator"
cout<< "Basal Metabolic Rate Calculator! " << endl;
}
//This functions purpose is to recive the prompted data the user
void getData (double& weight, double& age, double& height){

//print on screen, "Enter your weight"
cout <<"Enter your weight: ";
//wait for user input an store in 'weight'
cin >> weight;
//prompt the user to enter their age.
cout << "Enter your age: ";
//wait for input an store in 'age'
cin >> age;
//prompt the user to enter their height
cout << "Enter your height: ";
//wait for users input and store in 'height'
cin >> height;
}
//This functions purpose is to promt the user whether they're male or female
int getgender (){
//Declare a varaible called userinput that can hold whole numbers
int userinput;
//Prompt the user to answer whether they're male of female
cout << "Are you male or female? " << endl;
//print on screen "1. yes" and a line break
cout << "1. Female" << endl;
//print on screen "2. No" and a line break
cout << "2. Male" << endl;
//recieive input from user and store in userinput
cin >> userinput;
//return the value of userinput
return userinput;
}
//This function is responislbe for returning true of the user entered "1. female" or false if "2. Male" was entered.
bool specified (int option){
//check to see if option is 1
if (option == 1)
//return true
return true;
//if else
else
//return false
return false;
}


//male_female function: returns true if the user entered 1 and false otherwise
void calcData (bool initiated, double& weight, double& age, double& height){
//check to see if option is 1
if (initiated == true){
//calculator formula used to determine the female BMR
initiated = (655.1 + (9.6 * weight) + (1.8 * height) - (4.7 * age));

}
//if else, if option is not equal to 1, if else
else if (initiated = false);
//calculoator forumla used to determine the male BMR
initiated = (66.5 + (13.8 * weight) + (5.0 * height) - (6.8 - age));
}
//function deals with printing.
void printmessage (bool initiated){
//print on screen, "your BMR" follwed by "initiated" and a line break
cout << "your BMR: " << initiated << endl;
}


Last edited on
Are you supposed to implement this as a class?

And where are your calcData and printmessage implementations?

I just initialized option to 0, and initiated to false. I only get an error that says it is missing the definition of those two functions above.
Last edited on
Your program begins to fall apart at line 28 I believe. You call getgender, which has no parameters (passed by reference or otherwise), and it returns a value you do not store anywhere. I think what you're trying to do is:
(1) Store the value returned by getgender into your option variable.
(2) Pass your option variable into your specified function and store the return value of that into initiated.
(3) Call the calcdata function (which doesn't have a definition in the code provided. I don't know if it was omitted on purpose).
Keene's right. Your first call to getgender should be option = getgender().
yes, upon testing. It says option and initiated aren't intiallized. I've been tryingto understand why? However, you're right keen. I am trying to pass the results from getgender into options and then into initiated. Then from there calculate the users BMR based in those conclusions. I;m having difficulty, but going to try what you refereed to.
#include<iostream>
#include<string>

//Function Headers
using namespace std;
void greeting();
void getData (double& weight, double& age, double& height);
int getgender();
bool specified (int option);
void calcData (bool initiated, double& weight, double& age, double& height);
void printmessage (bool initiated);



//Main Fuction
int main(){

//Declare variables that can hold whole numbers.
int option;
//Declare varaibles that can hold decimal numbers
double weight, age, height;
//Declare a variable that can hold either true or false
bool initiated;

//Function Calls
greeting();
getData (weight, age, height);
getgender();
option = getgender();
specified (option);
initiated = false;
calcData (initiated, weight, age, height);
printmessage (initiated);


system ("pause");
return 0;
}

//This functions pupose serves an intrduction. Uses to adequetly specify the programs intent to the user.
void greeting(){
//print on screen, "Basal Metabolic Rate Calculator"
cout<< "Basal Metabolic Rate Calculator! " << endl;
}
//This functions purpose is to recive the prompted data the user
void getData (double& weight, double& age, double& height){

//print on screen, "Enter your weight"
cout <<"Enter your weight: ";
//wait for user input an store in 'weight'
cin >> weight;
//prompt the user to enter their age.
cout << "Enter your age: ";
//wait for input an store in 'age'
cin >> age;
//prompt the user to enter their height
cout << "Enter your height: ";
//wait for users input and store in 'height'
cin >> height;
}
//This functions purpose is to promt the user whether they're male or female
int getgender (){
//Declare a varaible called userinput that can hold whole numbers
int userinput;
//Prompt the user to answer whether they're male of female
cout << "Are you male or female? " << endl;
//print on screen "1. yes" and a line break
cout << "1. Female" << endl;
//print on screen "2. No" and a line break
cout << "2. Male" << endl;
//recieive input from user and store in userinput
cin >> userinput;
//return the value of userinput
return userinput;
}
//This function is responislbe for returning true of the user entered "1. female" or false if "2. Male" was entered.
bool specified (int option){
//check to see if option is 1
if (option == 1)
//return true
return true;
//if else
else
//return false
return false;
}


//male_female function: returns true if the user entered 1 and false otherwise
void calcData (bool initiated, double& weight, double& age, double& height){
//check to see if option is 1
if (initiated == true){
//calculator formula used to determine the female BMR
initiated = (655.1 + (9.6 * weight) + (1.8 * height) - (4.7 * age));

}
//if else, if option is not equal to 1, if else
else if (initiated = false);
//calculoator forumla used to determine the male BMR
initiated = (66.5 + (13.8 * weight) + (5.0 * height) - (6.8 - age));
}
//function deals with printing.
void printmessage (bool initiated){
//print on screen, "your BMR" follwed by "initiated" and a line break
cout << "your BMR: " << initiated << endl;
}


Topic archived. No new replies allowed.