So as the title says I am trying to create a leader board for a website I made. The goal of my c++ program was to sort the points for each player and then display the points from highest to lowest showing the name that correlates with their score. The problem that I need help with is after i sorted the points in the code, after they are sorted the player's name is no longer matched to the correct person. I cant figure out how to pair the player array with the score array again after they have been sorted. So if anyone could see what i could do or any tips would be amazing.
Also, the scores come from an outside source so i manually input scores each time this program is run.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
const int MAX_NAMES = 41;
using namespace std;
int main()
{
int points[MAX_NAMES];
int j = 1;
// Array of names of each person on the leaderboard.
string names[]
{
"Austin ",
"Jarred ",
"Cameron ",
"Mike ",
"Blake ",
"Mitch ",
"Juan ",
"Justus ",
"Avery ",
"Nick ",
"Garrett ",
"Dillion ",
"Ryan ",
"Andrew ",
"Brendan ",
"Justin ",
"Jared ",
"Steve ",
"Dylan ",
"Kylor ",
"Ian ",
"Josh ",
"Jake ",
"Kevin ",
"Nick ",
"Marco ",
"Patrick ",
"Danny ",
"Jay ",
"Bryson ",
"Mitchell ",
"Noah ",
"Tyler ",
"Andrew ",
"Evan ",
"Casey ",
"Mikey ",
"Hunter ",
"Luke ",
"Colton ",
"Harbir ",
};
// 1. Manually input score for each person and saves it into array.
cout << right << setw(50) << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" << endl;
cout << right << setw(55) << "INPUT TOTAL BETA POINT SCORE" << endl;
cout << right << setw(50) << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" << endl;
for (int i = 0; i < MAX_NAMES; i++)
{
cout << right << setw(40) << names[i] << " : ";
cin >> points[i];
}
// 2. organizes from highest to lowest
for (int k = 40; k >= 0; k--)
{
for (int x = 0; x < MAX_NAMES; x++)
{
if (points[x] < points[x + 1])
{
int temp = points[x + 1];
points[x + 1] = points[x];
points[x] = temp;
}
}
}
cout << right << setw(50) << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" << endl;
cout << right << setw(35) << "SORTED" << endl;
cout << right << setw(50) << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" << endl;
for (int i = 1; i < MAX_NAMES; i++)
{
cout << i << ") " << points[i] << endl;
}
// 3. Output totals into a html formatted file.
//ofstream outfile;
//outfile.open("total.txt")
system("pause");
return 0;
}