Passing Paremters troubles?

Hi peeps

I've tried to make a bmr calculator as a practice. So far it works perfectly, and i understand everything ive done. I want to put paremeter passing in and have the male bmr function as the calcululation only and have everything else in main. So that means passing age height weight which i sort of get. I think their would be less of it if i did it like that. Ive tried for hours and got no where. Ive put the main and the male function below. If anyone could offer any help I would be incredibly greatful. Thanks :)

#include <iostream>
using namespace std;

char sexselection[3];
void malebmr ();
void femalebmr ();
void activitylevel();



int main()
{
char restart;
int m;
int f;
int q;

do //to restart the programme once function is finished
{

cout<< "-------------MAIN MENU----------------" << endl;
cout<< "" <<endl;
cout<< "" <<endl;

cout<< "Please select your sex m or f" << endl; //Decision that determines which function is used
cin >> sexselection;


if(sexselection[0] == 'm')
{
malebmr();
}


else if(sexselection[0] == 'f')
{
femalebmr();
}

else if(sexselection[0] == 'q') //pressing the q will not run either function and end the programme
{
cout << "Quitting..." << endl;
}

cout<< "Would you like to run the programme again or quit? (R/Q)";
cin >> restart;
}
while (restart == 'r' ) ;

system ("pause");

}




void malebmr() //function to calculate a males bmr
{

int age; //variables that are local to this function
float weight; //Getting age, height and weight
float height;
int bmr;

cout <<"enter age:";
cin >> age;
cout << endl;

cout <<"enter height (cm):";
cin >> height;
cout << endl;

cout <<"enter weight (kg):";
cin >> weight;
cout << endl;


bmr = 66 + (13.7 * weight) + (5 * height) - (6.8 * age); //calculation to calculate the bmr

cout <<"your BMR is " << bmr << endl;

system ("pause");

}
In your void malebmr() definition, change bmr to a float data type (you have it as an int right now, but you are using floats in the calculation for it). After you do that, temporarily comment this part of your code like this:
1
2
3
4
/* else if(sexselection[0] == 'f')
{
femalebmr();
} */


now execute the program. should solve your immediate problem.
Brill. Thanks for that.

I've made a few changes regarding paremeter passing as well and this is as far as I have got. Struggling to proceed...

#include <iostream>
using namespace std;

char sexselection[3];
void malebmr (int age, float height, float weight);
void femalebmr ();
void activitylevel();


int main()
{
char restart;
int m;
int f;
int q;
float bmr;
int age; //variables that are local to this function
float weight; //Getting age, height and weight
float height;


do //to restart the programme once function is finished
{

cout<< "-------------MAIN MENU----------------" << endl;
cout<< "" <<endl;
cout<< "" <<endl;

cout<< "Please select your sex m or f" << endl; //Decision that determines which function is used
cin >> sexselection;


if(sexselection[0] == 'm')
{

cout <<"enter age:";
cin >> age;
cout << endl;

cout <<"enter height (cm):";
cin >> height;
cout << endl;

cout <<"enter weight (kg):";
cin >> weight;
cout << endl;


malebmr(age, height, weight);


}


else if(sexselection[0] == 'f')
{
femalebmr();
}

else if(sexselection[0] == 'q') //pressing the q will not run either function and end the programme
{
cout << "Quitting..." << endl;
}

cout<< "Would you like to run the programme again or quit? (R/Q)";
cin >> restart;
}
while (restart == 'r' ) ;

system ("pause");

}



void malebmr(age, height, weight)
{

bmr = 66 + (13.7 * weight) + (5 * height) - (6.8 * age);

cout <<"your BMR is " << bmr << endl;


}
What is the problem you are having now?
Trying to return the value from the malebmr to the main. Trying to cut the original programme down by using parameter passing. It wont accept the parameters in the function....
all you need to do is declare the variable type in your void malebmr function and in your case it is (int , float , float)
and then you declares bmr in wrong place. either you have to make it global and you declare it at the beginning or you declare it in your void function.

please use code tgs when writing codes. it is<>brackets next the window. it is easier to read the code like that.. thanx :)
Topic archived. No new replies allowed.