Function Call and "no match for operator>>"

Afternoon! I am trying desperately to wrap my head around function calling in C++. So I've written what I think is a very simple code:

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
#include <iostream>
#include <cmath>
using namespace std;

// * * * * * * * * * * * * * * * * * * * * * * * * * *
//                                                                  
//  Function:   basal_metabolic
//                                                                  
//  Purpose:    Calculates and returns the basal metabolic rate - the energy
//              needed to breath, maintain body temperature, etc.
//                                                                  
//  Parameters: pounds - weight of the user in pounds
//                                                                 
// * * * * * * * * * * * * * * * * * * * * * * * * * *
double basal_metabolic(double pounds_par);
				
int main()
{
	double weight, basal_metabolic_total;
	cout << "Enter your weight in pounds > ";
	cin >> weight >> endl;
	
	basal_metabolic_total = basal_metabolic(weight);
	
	cout >> basal_metabolic_total;

return(0);	
}
	
double basal_metabolic(double pounds_par)
{
	double basal_metabolic;
	double halfway = (pounds_par/2.2);    //calculates basal_matabolic before pow step
	basal_metabolic = 70 * pow(halfway, .756);
	
	return(basal_metabolic);
}


However, I'm pretty sure I didn't set up the call correctly, and can't figure out how to correct it. Also, I'm getting "no match for 'operator>>'" errors on lines 21 and 25.

Any help at all would be greatly appreciated :)
It appears you're trying to input to std::endl on line 21, and from std::cout on line 25, both of which being illegal.
Why are they illegal? This is exactly how I've written code for the past six months, and it's never had a problem with it before. Since I included using namespace std, shouldn't it be fine with the endl command?

I'm sorry, I don't understand :/
Line 25: You can't use >> with cout, I think you meant to use <<.

Line 21: You can't get input into std::endl, I'm not sure what you meant for that to be...
1
2
3
4
5
6
7
std::cout <<std::endl; //OK. Sends a newline to the standard output.
std::cin >>std::endl; //Wrong. It just makes no sense.

std::cout <<data; //OK. Sends data to the standard output.
std::cin >>data; //OK. Gets data from the standard input.
std::cout >>data; //Wrong.
std::cin <<data; //Wrong. 
Thank you to both of you. I'm being dumb today O.o
Okay, so I've now added a void function for the input, and now it's skipping over the basal_metabolic function. I have no idea why this is happening - this is almost word for word out of my book. The program will run and compile, and the input function works, but it doesn't call the calculation function for some reason.

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
#include <iostream>
#include <cmath>
using namespace std;


void input(int weight);

// * * * * * * * * * * * * * * * * * * * * * * * * * *
//                                                                  
//  Function:   basal_metabolic
//                                                                  
//  Purpose:    Calculates and returns the basal metabolic rate - the energy
//              needed to breath, maintain body temperature, etc.
//                                                                  
//  Parameters: pounds - weight of the user in pounds
//                                                                 
// * * * * * * * * * * * * * * * * * * * * * * * * * *
double basal_metabolic(double weight);
				
int main()
{
	double weight, basal_metabolic_total;
	
	input(weight);
	basal_metabolic_total = basal_metabolic(weight);
	
	cout << basal_metabolic_total;

return(0);	
}

void input(int weight)
{
	cout << "Enter your weight in pounds > ";
	cin >> weight;
	cout << endl;
}
	
double basal_metabolic(double weight)
{
	double basal_metabolic;
	//double halfway = (weight/2.2);    //calculates basal_matabolic before pow step
	//basal_metabolic = 70 * pow(halfway, .756);
	basal_metabolic = weight * 2;
	
	return(basal_metabolic);
}
	


Thank you so much for any help :D
You need to read up on how to pass parameters to functions and how to return values from functions.
The input function should either return the the weight value, or the weight parameter
should have been passed by reference
So just for clarification, if I want to use a void function, I have to make weight passed by reference, right? Because the input function can't return a value if it's a void function?
I made the value passed by reference and it worked. Thank you so much, guestgulken. I think I'm starting to understand this O.o
okapishomapi wrote:
Because the input function can't return a value if it's a void function?


Exactly.
Okay, I think I have it worked out. I just have one more issue. I have this main():

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
	double basal_metabolic_total, physical_activity_total, servings_needed, digestion_calories;
	int weight, intensity, minutes, calories;
	
	input(weight, intensity, minutes, calories);
	
	basal_metabolic_total = basal_metabolic(weight);
	physical_activity_total = physical_activity(weight, intensity, minutes);
	servings_needed = servings(weight, basal_metabolic_total, intensity, minutes, physical_activity_total, calories);
	digestion_calories = digestion(servings_needed, calories);

	output(weight, basal_metabolic_total, intensity, minutes, physical_activity_total, calories, servings_needed, digestion_calories);

return(0);	
}


which is obviously calling to all those other functions. Now I want to make it so that I can repeat the entire main -- but put the loop in another function.

Like, I just want to do a simple while loop (while answer ==Y || answer==y, else terminates), but I need it to be called as well. I have no idea how to do this. Any tips?
Topic archived. No new replies allowed.