I just learned about arrays and am having trouble getting them to pass to another function.
I have an array that gets fill with randomly generated scores then I'm suppose to pass that array to a function that will print all those scores. However, all it's doing right now is saying the score number and actual score is 0 along with some weird negative number randomly inserted in the middle.
The main is not supposed to do anything but execute the printStats function.
@TarikNeaj:
I watched the video but it doesn't help much. I can't specify what goes in the array. My problem is that once I fill the array in getScores, I need to pass it to printStats which is to print out the array but all I get is 0 and some random negative numbers.
No. When a program is run, only the main() is executed. When the main() ends, the whole program exits. Your main() calls printStat() and system(), but no other functions.
This is easy to test. Add a print command (like std::cout << "Hello\n";) into the getScores. Compile. Run.
The getScores() returns one double. That is why the line 16 is similar to: double scores[N] = { 3.27 };
What does that do? It does create an array of N double elements and initializes the first element with value 3.27.
Additionally, the remaining N-1 elements are initialized with value 0.0.
Your getScores() does not use its parameter at all and does out-of-range dereferencing.
Your getScore() converts the integer that rand() returns into a double and then converts the double into int. Why?
Here is a main() for you:
1 2 3 4 5 6 7
int main() {
constexprint X = 100;
double scores[X]; // uninitialized
getScores( scores, X );
printStat( scores, X );
return 0;
}