#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct Player {
string PlayerName;
int PlayerNumber;
int ScoredPlayer;
};
int main() {
const int NUM_PLAYERS = 12;
Player team[NUM_PLAYERS];
// ---- INPUT SECTION ----
for (int i = 0; i < NUM_PLAYERS; i++) {
cout << "Enter name of player " << (i + 1) << ": ";
// one-word names only (e.g., Alex, Brian, etc.)
cin >> team[i].PlayerName;
cout << "Enter number of player " << (i + 1) << ": ";
cin >> team[i].PlayerNumber;
while (team[i].PlayerNumber < 0) {
cout << "ERROR: number cannot be negative. Enter again: ";
cin >> team[i].PlayerNumber;
}
cout << "Enter points scored by player " << (i + 1) << ": ";
cin >> team[i].ScoredPlayer;
while (team[i].ScoredPlayer < 0) {
cout << "ERROR: points cannot be negative. Enter again: ";
cin >> team[i].ScoredPlayer;
}
cout << endl;
}
// ---- CALCULATE TOTAL POINTS + FIND TOP SCORER ----
int totalPoints = 0;
int maxIndex = 0; // index of player with most points
for (int i = 0; i < NUM_PLAYERS; i++) {
totalPoints += team[i].ScoredPlayer;
if (team[i].ScoredPlayer > team[maxIndex].ScoredPlayer) {
maxIndex = i;
}
}
// ---- DISPLAY TABLE ----
cout << "\nTEAM STATS\n";
cout << left << setw(12) << "Number"
<< left << setw(15) << "Name"
<< left << setw(10) << "Points" << endl;
cout << "----------------------------------\n";
for (int i = 0; i < NUM_PLAYERS; i++) {
cout << left << setw(12) << team[i].PlayerNumber
<< left << setw(15) << team[i].PlayerName
<< left << setw(10) << team[i].ScoredPlayer
<< endl;
}
// ---- DISPLAY TOTAL + TOP SCORER ----
cout << "\nTotal team points: " << totalPoints << endl;
cout << "Top scorer: " << team[maxIndex].PlayerName
<< " (number " << team[maxIndex].PlayerNumber
<< ") with " << team[maxIndex].ScoredPlayer
<< " points.\n";
return 0;
}