### Am I using Call-By-Value correctly? Instructions and Code provided

Certainly not done coding or formatting this, but so far this can calculate female Basal Metabolic Rate. Need to know if I'm utilizing call-by-values correctly(efficiently).

Also, if you're willing to take the time - after reading the instructions, help me rewrite this so that the user can input height in Feet and Inches, while the compiler converts this to inches (again, explained in instructions).

ANY and ALL help much appreciated. Have a couple of projects due at midnight.

 The program should calculate the person's Basal Metabolic Rate - the number of calories per day a person's body needs to function. Then, on the basis of calculated BMR, your program should output how many doughnuts a person can consume. A medium-size doughnut contains 251 calories. The BMR formula is as follows: for women: 655 + (4.3 x weight in pounds) + (4.7 x height in inches) - (4.7 x age in years) for men: 66 + (6.3 x weight in pounds) + (12.9 x height in inches) - (6.8 x age in years) Depending on gender, BMR should be calculated by functions bmrWomen() and bmrMen() that both accept three parameters: "weight in pounds", "height in inches" and "age in years" and return the BMR. Note that the BMR has a fractional part. The main function should prompt the user for her gender, weight, height and age; compute the BMR and the number of doughnuts that can be consumed per day; and then output both the BMR and the number doughnuts. The number of doughnuts is: BMR divided by the number of calories in a doughnut. Fractional number of doughnuts can be dropped. The number of calories per doughnut (251) should be put in a named constant. On the basis of the user's gender, main() function should decide whether to invoke bmrWomen() or bmrMen(). The user should input her height in feet and inches. The main() function should compute the total number of inches (one foot has 12 inches) and pass it to the bmr functions. Make sure to use the bmr function prototypes and put the function definitions below the main function definition.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950`` ``````#include using namespace std; void bmrWomen(); //void bmrMen(); int main() { int gender; cout << "Please Enter Your Gender" << endl << "Enter 1 for Female or 2 for Male: " << endl; cin >> gender; while (gender <= 0 || gender >= 3) { cout << "Invalid number" << endl; cout << "Please enter either 1 for Female or 2 for Male" << endl; cin >> gender; } if (gender == 1) { bmrWomen(); } //else //{ // bmrMen(); //} } void bmrWomen() { int weight; cout << "How much do you weigh in pounds? "; cin >> weight; int age; cout << "How old are you? "; cin >> age; int height; cout << "How tall are you (Enter total Inches)? "; cin >> height; double bmr; bmr = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age); cout << bmr; } ``````
Last edited on
Some things:

1. You're supposed to ask for the user's weight, age, and height in main and then pass those values to bmrWomen or bmrMen. So move lines 31-44 to somewhere in main.

2. The instructions say that those functions should take 3 parameters, calculate the BMR, and then return it back to main. Here is what a prototype might look like for bmrWomen:
`double bmrWomen(int weight, int height, int age);`
Then all you'd have to do is return the BMR that you calculate in the function, and do the rest of the calculations in main (the doughnuts part).

3. You can have the user enter in their height in feet first, then ask for the remaining inches, or have them enter them both on the same line. Then just multiply the number of feet that the user input by 12 and add it to the inches, and you have total height in inches.

4. Don't forget to return something from main.
Last edited on
Appreciate the help. Our class was just introduced to Call-by-Value - and our teacher hardly speaks enough English to read the instructions to us :)
Topic archived. No new replies allowed.