Soccer Score

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;


const int SIZE = 50;
struct Player
  {
	char name[SIZE];        //Player's Name
	int playNum;            //Player's Number
	int Points;          //Point's Scored
};

const int 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;
}
Last edited on
Topic archived. No new replies allowed.