array problem

the following code is supposed to read an array of exam scores for a lecture section of up to max_size students. But I am getting an error that follows the code, could someone kindly help figure what is wrong with this code:

thanks,
upad
-----------------------------------

# include <iostream>
# include <cmath>
# include <string>

using namespace std;

const int max_size=5;
void readScores(int, int, int&);

int main()
{
int scores[max_size];
int sectionSize=0;
readScores(scores[max_size], max_size, sectionSize);

system ("pause");
return 0;
}

void readScores(int scores[], int max_size, int& sectionSize)
{
const int SENTINEL=-1;
int tempScore;
cout << "Enter next score after the prompt or enter " << SENTINEL << " to stop." << endl;
sectionSize=0;

cout << "score: ";
cin >> tempScore;

while ((tempScore != SENTINEL) && (sectionSize< max_size))
{
scores[sectionSize] = tempScore;
sectionSize++;
cout << "score: ";
cin >> tempScore;
}

if (tempScore != SENTINEL)
{
cout << "Array is filled!" << endl;
cout << tempScore << "not stored" << endl;
}
}
----------------------------------------------
warning C4700: uninitialized local variable 'scores' used
1>L9.6.obj : error LNK2019: unresolved external symbol "void __cdecl readScores(int,int,int &)" (?readScores@@YAXHHAAH@Z) referenced in function _main
1>C:\Users\Owner\Documents\Visual Studio 2010\Projects\Ch9.5\Debug\Ch9.5.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
readScores expect an array, but you are passing a value
1
2
readScores(scores[max_size], max_size, sectionSize); //pass an int
readScores(scores, max_size, sectionSize); //pass int[] 


Also the index goes from 0 to n-1, so this is out of range scores[max_size]
1) above suggestion (readScores(scores, max_size, sectionSize);) is giving the following error:

error C2664: 'readScores' : cannot convert parameter 1 from 'int [5]' to 'int'
1> There is no context in which this conversion is possible
-------------------------------------------------------------------------------------------------------------------
2) also scores[5] implies array size and not the subscript, so I'm thinking there is nothing wrong with that.
Having said that, I am still not sure how to correct the above code...any help??
1
2
3
4
void readScores(int, int, int&); //prototype
void readScores(int scores[], int max_size, int& sectionSize){ //definition
//...
}

Your prototype doesn't match. Both should be void readScores(int [], int, int&);


also scores[5] implies array size and not the subscript

No. If you aren't declaring it, it's subscript
Topic archived. No new replies allowed.