Questions about passing values to functions

Jul 29, 2013 at 2:17am
Hey guys, first time posting so i hope im not completely retarded with my code. Basically what im trying to do is get the scores of category, then pass them to the calc_calc function for processing. everything works fine until the values need to be passed. I was wondering if im completely wrong here or if its a quick fix. Thanks alot for your help!

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

float calc_calc(float, float, float, float, float);

float calc_calc(float mid, float final, float research, float group, float part)
{
mid *= .25;
final *= .25;
research *= .20;
group *= .20;
part *= .1;

return mid + final + research + group + part;
}


int main()
{
	double mid;
	double final;
	double research;
	double group;
	double part;

	cout << "Please enter your midterm score: ";
	cin>>mid;
	cout <<"\n Please enter your final score: ";
	cin>>final;
	cout << "\n Please enter your research paper score: ";
	cin>>research;
	cout<<"\n Please enter your group project score: ";
	cin>>group;
	cout<<"\n Please enter your participation score: ";
	cin>>part;

	calc_calc(mid,final,research,group,part);


system("pause");
return 0;
}
Jul 29, 2013 at 2:22am
What's actually going wrong? It looks fine to me but you haven't said what is making you think it isn't working like it should.
Jul 29, 2013 at 2:23am
That all looks fine and dandy to me.

But you're not actually using the value calc_calc returns, so how do you know it's going wrong?
Jul 29, 2013 at 3:57am
well im not getting any output for the function calc_calc....or did i miss something, i thought that after the calc_calc function ran it would return the grade to me.
Last edited on Jul 29, 2013 at 3:57am
Jul 29, 2013 at 7:09am
It is, but you aren't doing anything with the value it gives you. Perhaps you meant to cout<< it?
Jul 29, 2013 at 7:47am
cout line 37.
Jul 29, 2013 at 8:48am
You need to pass the values by reference to the function.
Jul 29, 2013 at 9:59am
You need to pass the values by reference to the function.


If you need the changed values of mid, final, etc to be passed back to the main function, then you need to pass them by reference. Nothing in the OP's code suggests that that's the case, though.

As others have said, the problem is that the code isn't actually doing anything with the returned value. calc_calc is returning the value, but the main function is ignoring it.
Last edited on Jul 29, 2013 at 9:59am
Topic archived. No new replies allowed.