Trying to get it to name player who score the most
points. Got a hang-up somewhere. Please help.
Does the rest fine except for the last requirement and that is to name the player who scored the most pts.
Thanks,
#include <iostream.h>
#include <stdlib.h>
struct PlayerInfo
{
char name[25];
int playerNum;
int pointsScored;
};
void main(void)
{
PlayerInfo players[12]; //array of 12 structs
int number = 0;
int index = 0;
int totalPoints = 0;
char y;
cout << "Soccer Scores" << endl << endl;
cout << "How many players do you want to enter? ";
cin >> number;
cout << endl;
for (index = 0; index < number; index++)
{
cout << "Player #" << (index + 1) << "\n--------------\n";
cout << "Player's name: ";
cin.ignore();
cin.getline(players[index].name, 25);
cout << "Player's number: ";
cin >> players[index].playerNum;
while (players[index].playerNum < 0)
{
cout << "Please enter a positive number for player's number ";
cin >> players[index].playerNum;
}
cout << "Points scored: ";
cin >> players[index].pointsScored;
while (players[index].pointsScored < 0)
{
cout << "Please enter a positive number for points scored ";
cin >> players[index].pointsScored;
}
cout << endl;
}
cout << "NAME\t" << "NUMBER\t" << "POINTS SCORED\n";
for (index = 0; index < number; index++)
{
cout << players[index].name << "\t" << players[index].playerNum
<< "\t" << players[index].pointsScored << endl;
totalPoints = totalPoints + players[index].pointsScored;
}
cout << "TOTAL POINTS: " << totalPoints << endl;
int temp;
for (index = 0; index < number; index++) // sort to find highest score
for ( int y = 0; y < number; y++)
{
if (players[y].pointsScored > players[index].pointsScored)
{
temp = players[index].pointsScored;
players[index].pointsScored = players[y].pointsScored;
players[y].pointsScored = temp;
}
}
//How do I convert highest score into name who had highest score
for(index +1 + number; index <= number; index++)
{
cout << "The player who scored the most points is: " << players[index].name;
}
cout << endl;
system("PAUSE");
}
I like your idea much better. Thanks.
The bubble seems like it would be overkill. Your idea makes better sense.
Got it to work. Thanks for the direction.
Sometimes all it takes is to be pointed down the right path.
Thanks dude