Help with pass by value, and results by variable

I need help with my online c++ assignment.

The instructions:
A nutritionist who works for a fitness club helps members by evaluating their diets.As part of her evaluation, she asks members for the number of fat grams and carbohydrate grams that they consume in a day. Then, she calculates the number of calories that results from the fat using the following formula:

Calories from fat = fat grams x 9

Next, she calculates the number of calories that result from the carbohydrates using the following formula:

Calories from Carbs = Carbs grams x 4

Create an application that will make these calculations

•DO NOT use global variables
•Create two variables in main that will hold the two results
•Pass fat and carbs by value, and the result variables by reference
•Output in main
The key with what you need to pass is this: Pass fat and carbs by value, and the result variables by reference

This is what I have to far but I don't understand how to "pass by value, and results by variable"


#include <iostream>
using namespace std;

void grams (int);
void calories ();

int main ()
{

//Get fat and carb grams
grams ();

//convert to calories
calories ();

//Display results
cout << "Today you consumed ", fatcalories, "calories from fat";
cout << "Today you consumed ", carbcalories, "calories from carbs";

system("pause");
return 0;
}

//Get grams
void grams(int ref value);
{

cout << "Please enter then number ";
cout << "of fat grams you consumed today.";
cin >> fatgrams;
cout << "Please enter then number ";
cout << "of carb grams you consumed today.";
cin >> carbgrams;
}
//conver to calories
void calories (int &num)
{
set fatcalories = fatgrams * 9
set carbcalories = carbgrams * 4
}
Last edited on
See section "Arguments passed by value and by reference" in http://www.cplusplus.com/doc/tutorial/functions/
Topic archived. No new replies allowed.