What's wrong with my code?

Hey guys, I'm trying to finish up a homework assignment and I can't figure out why it won't compile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  #include <iostream>
#include <cmath>
using namespace std;
void displayDescription(); //displays greeting to user
void caloriesDIGESTION();//calculates the calories required for digestion
void caloriesreqBASAL(); //calculates basal metabolic rate
void caloriesreqPHYSICAL(); //calculates calories used for physical activity
double caloriesNEEDED(double);//calculates calories needed to main body weight
void displayRESULT();//displays the result of calories needed to user

int main()
{
    //variable declarations
    double lbs, physicalActivity, calories, caloriesREQ, minutes, totalCal;
    double const caloriesREQdigest= calories * 0.1;

    //display greeting
    displayDescription();
    //Get informaton from user
    cout << "How much do you weigh in lbs? \n";
    cin>>lbs;
    cout << "\nPlease estimate the intensity of your workout  \n"
         << "(Ex. Running @10 MPH=17, Running @ 6PMH=10, Basketball=8, & Walking=1): \n";
    cin>> physicalActivity;
    cout << "\nHow long (in minutes) do you perform this physical activity?\n";
    cin>> minutes;
    //displays result to user
    displayRESULT(totalCal);

    return 0;
}
void displayDescription()
{
    cout <<"Hello, this program will allow you to calculate how many servings of a \n"
         <<"certan food you need to intake to maintain your body weight \n\n";

}
void caloriesreqBASAL()
{
    double lbs, caloriesREQbasal, weight;
    caloriesREQbasal= 70.0 * pow((weight/2.2), 0.756 );

}
void caloriesreqPHYSICAL()
{
    char running;
    double lbs, caloriesREQphysical, physicalActivity, intensity, minutes, mph;
    caloriesREQphysical= 0.0385 * intensity * lbs * minutes;
    cout<< "What kind of physical exercise did you do today?";
    cin>>physicalActivity;

}
void caloriesDIGESTION()
{
    double caloriesREQdigestion, calories;
    caloriesREQdigestion= calories*0.1;
}
double caloriesNEEDED()
{
    double totalCal, caloriesREQdigestion, caloriesREQbasal, caloriesREQphysical;
    totalCal = caloriesREQbasal + caloriesREQphysical + caloriesREQdigestion;
    return totalCal;
}
void displayRESULT(double totalCal)
{

    //displays the amount of calories needed
    cout << "The total amount of calories needed to maintain your body weight is: ";
}
Last edited on
What are the exact error messages?

on line 28: error: no matching function for call to 'displayRESULT'

also,

for line 9: note:candidate function not viable: requires 0 arguments, but 1 was provided.
Last edited on
Does your function prototype match your function call and function implementation? They all need to agree as to the number and type of parameters.

Ok, so I realized that I forgot to include the "double" type in line 9:
 
void displayRESULT(double);//displays the result of calories needed to user 


It now compiles, but when the program is supposed to display the calories needed, it's blank.

line 68:
 
  std::cout << "The total amount of calories needed to maintain your body weight is: " << totalCal << std::endl;
You mean it prints: "The total amount of calories needed to maintain your body weight is: " and nothing else, correct?

Where do you actually try to print a value to go along with that text?

Also you have several functions that you never call, why? In those functions you have calculations using variables that have never been assigned values.

So my recommendation is that you take some time and look up a couple of things:

1. Variable scope: http://en.cppreference.com/w/cpp/language/scope
2. Functions : http://www.cplusplus.com/doc/tutorial/functions/

Last edited on
So my recommendation is that you take some time and look up a couple of things:

1. Variable scope: http://en.cppreference.com/w/cpp/language/scope
2. Functions : http://www.cplusplus.com/doc/tutorial/functions/



sorry jib.
closed account (48T7M4Gy)
Try this. Read it carefully and you will be able to see what the above comments mean at first hand with a bit of luck - functions and parameters especially. It's not complete and may not be accurate so don't just copy it. I also changed a few of the names in the hope that it is clearer and self-documenting and therefore limits comments.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <cmath>

using namespace std;

void displayGreeting();

double caloriesreqBASAL(double);
double caloriesreqPHYSICAL(double, double, double);

void displayRESULT(double);

int main()
{
	double weight = 0, totalCalories = 0, minutes = 0;
	double physicalActivity = 1;

	displayGreeting();

	cout << "How much do you weigh in lbs?: ";
	cin >> weight;

	cout << "\nPlease estimate the intensity of your workout  \n"
		<< "(Ex. Running @10 MPH=17, Running @ 6PMH=10, Basketball=8, & Walking=1): \n";
	cin >> physicalActivity;

	cout << "\nHow long (in minutes) do you perform this physical activity?\n";
	cin >> minutes;

	double BASAL = caloriesreqBASAL(weight);
	double PHYSICAL = caloriesreqPHYSICAL(weight, physicalActivity, minutes);

	totalCalories = BASAL + PHYSICAL;

	displayRESULT(totalCalories);

	system("pause"); // :)

	return 0;
}

void displayGreeting()
{
	cout << "Hello, this program will allow you to calculate how many servings of a \n"
		<< "certan food you need to intake to maintain your body weight \n\n";
}

double caloriesreqBASAL(double aWeight)
{
	double calBASAL = 0;
	calBASAL = 70.0 * pow((aWeight / 2.2), 0.756);
	return calBASAL;
}

double caloriesreqPHYSICAL(double aWeight, double anIntensity, double someMinutes)
{
	double physical = 0.0385 * anIntensity * aWeight * someMinutes;
	return physical;
}

void displayRESULT(double total)
{
	cout << "Total calories to maintain your body weight: " << total << " calories" << endl;
}
Last edited on
Topic archived. No new replies allowed.