Value Returning Functions

I'm having an issue writing this program. I am supposed to write a program to calculate 3 test scores and find an average using functions. I have to call the two functions getTestScore and calcAverage. Im just not understanding this I guess. Im quite new so mind my ignorance. This is my code, any help would be great. Thanks again.

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
// chapter9 Scott Jorgensen

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

//prototypes
int getTestScores();
double calcAverage(int average, int testScores);


int main()
{
	double testScores = 0.0;
	double average = 0.0;

	testScores = getTestScores();
	average = calcAverage();

	//display
	cout << fixed << setprecision (2);
	cout << "Average: " << average << endl;


	system("pause");
	return 0;


}

//fuction defs

int getTestScores()
{
	int test1 = 0;
	int test2 = 0;
	int test3 = 0;
	int testScores = 0;

	cout << "Test Score 1: ";
	cin >> test1;
	return test1;
	cout << "Test Score 2: ";
	cin >> test2;
	return test2;
	cout << "Test Score 3: ";
	cin >> test3;
	return test3;

	testScores = test1 + test2 + test3;
	return testScores;
}

double calcAverage(int average, int testScores)
{
	double averageScore;
	
	averageScore = testScores / 3; 
	return averageScore;
}//end
closed account (zb0S216C)
When a return[1] statement is encountered within a function, it ends the function by returning the specified value.

[Note: Functions cannot return multiple values]

References:
[1]http://msdn.microsoft.com/en-us/library/k68ktdwf(v=vs.80).aspx


Wazzak
Last edited on
Good attempt, your very close.

Your call in main to calcAverage is missing parameters.
Also you don't need to pass in average to calcAverage, it returns it.
Change
double calcAverage(int average, int testScores);
to
double calcAverage(int testScores);

remove the following 3 lines from getTestScores. The first return hit is the end of the fuction.
1
2
3
return test1;
return test2;
return test3;


Also change the following line in calcAverage function. Casting testScoures from int to double, this forces the divide to be real not integer.
averageScore = testScores / 3;
to
averageScore = (double)testScores / 3;

oh ok. well i feel stupid. ok i removed the multiple returns but still getting the error calcAverage "function does not take 0 arguments"

edit:: O ok i made all those changes and still getting the above error. You guys have always been a ton of help thanks in advanced.
Last edited on
closed account (zb0S216C)
In addition to BinaryBob's post, the linker is trying to look for calcAverage( void ), not
calcAverage( int, int ).

Wazzak
ok now it works. I dont think id ever understand all this if this forum didnt exist. Thanks again.
Topic archived. No new replies allowed.