Hi, I'm working with dynamic arrays and I'm trying to sort a string array based off of the indexes of an int array that has been sorted in descending order.
I'm trying to figure out how to display the names associated with the corresponding scores. The scores are sorted properly but the names aren't in the correct order. Here is what I have so far:
when my code is displayed, it just lists the names in the entered order, but I want to be able to sort my names so that they match scores associated with them.
Sample output:
(notice the names do not correspond with their scores in the top scorers section)
How many scores will you enter?: 4
Enter the name for score #1: Jack
Enter the score for score #1: 40
Enter the name for score #2: John
Enter the score for score #2: 35
Enter the name for score #3: Rick
Enter the score for score #3: 37
Enter the name for score #4: Bobby
Enter the score for score #4: 23
Top Scorers:
Jack: 40
John: 37
Rick: 35
Bobby: 23
Press any key to continue . . .
When you're swapping elements in the score array, also swap the elements in the names array.
But there's issues because the swap is based off of integers, not strings. I'm wondering if there's a way to equate the elements of my score array with my names array after swapping?
I tried adding this,
1 2 3 4
temp = scores[minIndex];
scores[minIndex] = scores[startScan];
names[minIndex] = names[startScan]; //added this and it made it worse
scores[startScan] = temp;