Alright, so I have coded this program so far and it compiles just fine. It crashes after reading user input for the 10th score, so after the 1st FOR loop.
I can't seem to find the issue and I'm not yet done with the program, I have yet to figure out how to out put the scores descending and the names alphabetically.
#include "stdafx.h"
#include <iostream>
#include <istream>
#include <string>
#include <algorithm>
#include <cstdlib>
usingnamespace std;
int main()
{
string player_names[10]; //Array for player names
string player_scores[10]; //Array for player scores
string nameIN; //variable to hold name
string scoreIN; //variable to hold score
for( int i=1; i < 11; i++) //For loop
{
cout << "Please enter name and score for Player " << i << "\n" << endl; //Ask user to input name and score
cout << "Name: \n";
cin >> nameIN;
cout << "Score: \n";
cin >> scoreIN;
player_names[i] = nameIN+" "+scoreIN; //To store name, then score
player_scores[i] = scoreIN+" "+nameIN; //To store score, then name
}
sort(player_scores, player_scores+10); //Sorting
for( int i=10; i>=0; i--)
{
cout << player_scores[i] << "\n";
}
system("pause");
return 0;
}
Yes, I realize that I initialized scoresIN as a string instead of integer, this is because I can't put an integer array into a string array. This is so I can sort them later.
Any help, suggestions, or opinions are greatly appreciated!!!