[School]Stumped

I am stumped with this problem for my c++ class. We are supposed to have a function called stat that reads in the # of #'s in an array, the array itself, and 3 blank values to become the min/max/average. We have to use the prototype exactly as it is and the main function exactly as it is, and when i test it in VS 2010 it says it is fine, but when i compile it returns
Array.obj : error LNK2019: unresolved external symbol "int __cdecl stat(int,int
const * const,int &,int &,int &)" (?stat@@YAHHQEBHAEAH11@Z) referenced in functi
on main
Array.exe : fatal error LNK1120: 1 unresolved externals


What do i need to do to fix this?

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>
using std::cin;
using std::cout;
using std::endl;

int stat(int, const int[], int&, int&, int&);
int readArray(int, int[]);

int main()
{
	const int MAX_SCORE = 50; // the maximum # of scores that a user can enter
	int score[MAX_SCORE]; // create storage for up to 50 scores
	int nScores = readArray(MAX_SCORE, score); // read array and return count

	int avgScore, minScore, maxScore;
	if (stat(nScores, score, avgScore, minScore, maxScore) == 0)
	{
		cout << "Average=" << avgScore << endl
			<< "Max=" << maxScore << endl
			<< "Min=" << minScore << endl;
	}
	else
		cout << "No Data" << endl;
	return 0;
}
int readArray(const int MAX_SCORE, int score[])
{
	int nScores = 0; // count the number of scores entered
	
	cout << "Enter up to 50 numbers. Enter a -1 after the last score is entered." << endl;
	// read the scores from the keyboard, space and/or newline delimited
	for (int i = 0; i < MAX_SCORE; i++)
	{
		cin >> score[i];
		if (score[i] < 0)
			break; // enter no more scores after the 1st negative is found
		else
			nScores++; // count the score if it is non-negative
	}
	return nScores;
}
int stat(int nScores, int score[], int avgScore, int minScore, int maxScore)
{
	int scorex[50];
	for (int z = 0; z < nScores; z++)
		scorex[z] = score[z];
	double avg = 0;
	if (nScores == 0)
	{
		return 1;
	}
	else
	{
		for (int x = 0; x < nScores; x++)
		{
			avg = avg + scorex[x];
		}
		avg = avg / nScores;
		for (int y = 0; y < nScores; y++)
		{
			if (scorex[y] > maxScore)
				maxScore = scorex[y];
			if (scorex[y] < minScore)
				minScore = scorex[y];
		}
		avgScore = avg;
		return 0;
	}
}
You forgot the &'s after the int parameters in your implementation. You linker is looking for a definition of
 
int stat(int, const int[], int&, int&, int&);
but it only finds int stat(int nScores, int score[], int, int , int)
Last edited on
So line 42 should be
int stat(int nScores, int score[], int& avgScore, int& minScore, int& maxScore)
???
No, the ampersand belongs after the variable name.
No, the ampersand belongs after the variable name.
???
You mean like this?
int stat(int nScores, int score[], int avgScore&, int minScore&, int maxScore&)
Are you feeling alright? That's not valid C++ at all.
trobbers405's assumption is correct. That's how reference parameters are declared.
try
 
int stat(int nScores, int score[], int avg&Score, int min&Score, int max&Score)


source:
http://tinyurl.com/3rmd84u
Last edited on
^wat

No.
The function header for the definition doesn't match the prototype. It should be

1
2
3
4
int stat(int nScores, const int score[], int &avgScore, int &minScore, int &maxScore)
{
     // stuff
}
I think your problem is that your function's parameter list is different in the declaration and the definition.

I think...

I'm not sure though, see other posts.

source:
http://tinyurl.com/3rmd84u
It wasn't funny the first time. It won't be funny the second or third time.
lol wut. u mad?
True, I wasn't feeling alright at the time. Sorry.
Topic archived. No new replies allowed.