// Can Someone help me with the last function at the bottom. I am trying to display the top scorers, not just top scorer. If someone could point me in the right direction it would be greatly appreciated.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct Players
{
string name;
int numPlayer; //Number of the Player
int numPoints; //Point's scored by Player
};
const int SIZE = 50;
const int MAXPLAYERS =2;
typedef struct Players Roster[2];
int total;
int maxgoals = 0;
void Greeting ();
void TotalPoints (Roster &Players);
void HighestScore (Roster &Players);
void DisplayAll (Roster &Players);
int main ()
{
Roster SoccerPlayers;
Greeting();
for (int index=0; index< 2; index++) // put this in a function
{
cout << "Enter Player's Name: ";
getline(cin, SoccerPlayers[index].name);
;
do
{
cout << "Enter Player's Uniform Number: ";
cin >> (SoccerPlayers[index].numPlayer);
if (SoccerPlayers[index].numPlayer<=0)
cout << "Zero or negative number not allowed, Try Again" << endl;
}while (SoccerPlayers[index].numPlayer<=0);
do
{
cout << "Enter Player's Points: ";
(cin >> SoccerPlayers[index].numPoints).get();
if (SoccerPlayers[index].numPoints<=0)
cout << "Zero or negative number not allowed, Try Again" << endl;
}while (SoccerPlayers[index].numPoints<=0);
cout << endl;
}
DisplayAll(SoccerPlayers);
TotalPoints(SoccerPlayers);
HighestScore(SoccerPlayers);
return 0;
}
void Greeting ()
{
cout << "___________________________________________________" << endl;
cout << "Welcome to the Soccer Team Data Analyzer" << endl;
cout << "You will now be asked to enter the name" << endl;
cout << "uniform number, and points earned for each player." << endl;
cout << "___________________________________________________" << endl;
}
void DisplayAll (Roster &SoccerPlayers)
{
cout << "Players Score Summary" << endl << endl;
cout << "__________________________________________" <<endl;
cout << "Name Number Score" << endl;
cout << "__________________________________________" << endl;
for (int index=0; index< MAXPLAYERS; index++)
{
cout << setw(20) <<left << SoccerPlayers[index].name;
cout << setw(15) <<left << SoccerPlayers[index].numPlayer;
cout << SoccerPlayers[index].numPoints << endl;
}
}
void TotalPoints (Roster &SoccerPlayers)
{
int TotalScore = 0;
for (int index = 0; index < 2; index++)
{
TotalScore += (SoccerPlayers[index].numPoints);
}
cout << "The total score is: " << TotalScore << endl;
}
void HighestScore (Roster &SoccerPlayers)
{
string firstPlaceIndex;
string secondPlaceIndex;
int max = SoccerPlayers[0].numPoints;
// Loop that runs through and each player and compares one player in the array w/ the one next to them
for (int index = 0; index < MAXPLAYERS; index++)
{
if (SoccerPlayers[index].numPoints > max)
{
firstPlaceIndex= SoccerPlayers[index].name;
secondPlaceIndex= SoccerPlayers[index].name;
}
}
cout << "The highest scorers are: " << firstPlaceIndex << "&" << secondPlaceIndex << endl;
}