I am trying to complete this program but am stuck.
Soccer Scores. Write a program that stores the following data about a soccer player in a structure: Player’s name, Player’s number, Points scored by Player. The program should keep an array of 12 of these structures. Each element is for a different player on a team. The program should ask the user to enter information for each player. It should then display a table that lists each player’s number, name and points scored. The program should also calculate and display the total points earned by the team. The program should also determine which player earned the most points on the team and display that player’s information. Validation: Do not accept negative values for player’s number or points scored. I set the NUM_PLAYERS to 3 to simplify the trouble shooting. I also just realized void showHighest(Player[], int); is not being used. Any help would be great. I already turned this assignment in but want to get it right. My output is wrong. total points for team and the person with the highest points does not come out right.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
constint SIZE = 50;
struct Player
{
char name[SIZE]; //Player's Name
int playNum; //Player's Number
int Points; //Point's Scored
};
constint NUM_PLAYERS = 3; //Number of Players
// Dynamically allocate the memory needed.
Player *players = new Player[NUM_PLAYERS]; //Array of structures
int total = 0;
void getPlayerInfo(Player &);
void showInfo(Player);
int getTotalPoints(Player[], int);
void showHighest(Player[], int);
int main()
{
getPlayerInfo(*players);
getTotalPoints(players,total);
showInfo(*players);
}
void getPlayerInfo(Player&)
{
int index;
// Get Player data.
cout << "\nYou will need the following information.\n";
cout << "Pertaining to your Soccer Players.\n";
cout << "The Player's Names, Player's Numbers\n";
cout << "Finally you will need the Points Scored by Players.\n\n\n";
for (index = 0; index < NUM_PLAYERS; index++)
{
cout << "Please enter the Player's Name: ";
cin.getline(players[index].name, 50);
cout << "Please enter the Player's Number: ";
(cin >> players[index].playNum).get();
//To test my values for zero, negative
while (players[index].playNum <= 0)
{
cout << "Zero or negative numbers not allowed\n";
cout << "Please enter the Player's Number: ";
(cin >> players[index].playNum).get();
}
cout << "Please enter the Points Scored by the Player: ";
(cin >> players[index].Points).get();
//To test my values for zero, negative.
while (players[index].Points < 0)
{
cout << "Zero or negative numbers not allowed\n";
cout << "Please enter the Points Scored by the Player: ";
(cin >> players[index].Points).get();
}
cout << endl << endl;
}
return;
}
int getTotalPoints(Player[], int)
{
int index;
int total = 0;
//Calculate the total points
for (index = 0; index < NUM_PLAYERS; index++)
{
total += players[index].Points;
}
int TotalPoints(int *, int);
return total;
}
void showInfo(Player)
{
int TotalPoints = 0;
int index = 0;
//Display the players data
cout << "Here is the players data:\n\n";
cout << " Name Number Score \n";
cout << "--------------------------------\n";
for (index = 0; index < NUM_PLAYERS; index++)
{
cout << setw(8) << players[index].name;
cout << setw(8) << players[index].playNum;
cout << setw(8) << players[index].Points << endl;
}
//Display the results of the total points.
cout << "\n\nThe total of points scored by the team are: ";
cout << TotalPoints << endl;
//To get the player with most points
int max = players[0].Points;
int maxIndex = 0;
for (int index = 0; index < 12; index++)
{
if (players[index].Points > max)
{
max = players[index].Points;
maxIndex = index;
}
}
cout << "highest score by: " << players[maxIndex].name << " number: " << players[maxIndex].playNum << endl;
return;
}