Displaying scores - Array

I'm having trouble with the last function of this assignment:

Make a program that will search through scores of an array and display the scores in descending order to simulate a high score leaderboard. The program should contain the following:


main() - In main, declare an array called scores[]. Ask the user for 5 scores. Store the 5 scores in scores[]. Call a function called sortScores() and pass the array by reference. Call a function called displayScores(). Pass the array by value into that function.

sortScores() - This function will accept an array passed by reference and the size of the array. The function will use the selection sort algorithm to sort through array. You will need to modify the algorithm to sort the scores from greatest to least. This function returns no data.

displayScores() - This function accepts an array passed and will cout the contents of the array. Hint: You can use this function during development to see the array unsorted and sorted.

I'm doing something wrong because my sorted scores aren't showing up. Any help would be greatly appreciated :)

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
#include <iostream>
#include <algorithm>

using namespace std;

void sortScores(int scores[5], int size);
void displayScores(const int scores[5]);

int main()
{
	int scores[5];

	cout << "Enter 5 scores: " << endl;

	for (int i = 0; i < 5; ++i)
	{
		cin >> scores[i];
	}

	return 0;
}

void sortScores(int scores[5], int size)
{
	int startScan, minIndex, minValue;

	for (startScan = 0; startScan < (scores[5] - 1); startScan++)
	{
		minIndex = startScan;
		minValue = scores[startScan];
		for (int index = startScan + 1; index < 5; index++)
		{
			if (scores[index] > minValue)
			{
				minValue = scores[index];
				minIndex = index;
			}
		}
		scores[minIndex] = scores[startScan];
		scores[startScan] = minValue;
	}
}

void displayScores(const int scores[5])
{
	for (int count = 0; count < scores[5]; count++)

		cout << "THE TOP SCORES:" << endl;
		cout << scores[5] << endl;

	cout << endl;
}
You may pass the scores array by call by reference
If you don't mind, could you explain a bit more in detail?
Topic archived. No new replies allowed.