Good Morning. I was working on a C++ program last night and thought it had come to completion. It asks for soccer scores,players info using structure and outputs totals, plus team score and highest player. Supposed to use pointers, dynamic memory and passes through functions. I had everything working and then changed one thing and now when it compiles it looks like a big mess. Any suggestions? Thanks for help. Ed
// function declarations
void getTotal(PlayerInfo[], int);
void findHighest(PlayerInfo[], int);
int main()
{
const int SIZE = 3;
PlayerInfo soccer[SIZE];
cout << "Enter the Player Information below\n";
cout << "----------------------------------\n";
for (int i = 0; i < SIZE; i++)
{
cout << "\nEnter Player # " << (i + 1) << " Name: ";
cin >> soccer[i].name;
cout << "\nEnter Player # " << (i + 1) << " Jersey number: ";
cin >> soccer[i].playerID;
while (soccer[i].playerID < 0)
{
cout << "Please enter a number greater than zero: ";
cin >> soccer[i].playerID;
}
cout << "\nEnter the points scored by Player #" << (i + 1) << ": ";
cin >> soccer[i].points;
while (soccer[i].points < 0)
{
cout << "Please enter a number greater than zero: ";
cin >> soccer[i].points;
}
}
cout << "\n\n";
void displayPlayers(int i);
cout << "Name ID Number Players Score " << endl;
cout << "----------------------------------------------\n";
for (int i = 0; i < SIZE; i++)
{
cout << setw(1) << soccer[i].name;
cout << "\t\t" << soccer[i].playerID;
cout << "\t\t" << soccer[i].points << endl;
}
}
cout << "\n\n";
//Function call to Total points
getTotal(soccer, SIZE);
cout << "\n\n";
cout << "\n\n";
//Function call to Highest points
findHighest(soccer, SIZE);
system ("pause");
return 0;
}
void getTotal(PlayerInfo ptr[], int SIZE)
{
int total = 0;
for (int i = 0; i < SIZE; i++)
{
total = ptr[i].points + total;
cout << "The total points added by player to the team: " << total << endl;
}
}
void findHighest(PlayerInfo ptr[], int SIZE)
{
int max = 0;
for (int i = 0; i < SIZE; i++)
{
if (ptr[i].points > max)
max = ptr[i].points;
}
for (int i = 0; i < SIZE; i++)
{
if (ptr[i].points == max)
{
cout << "The player that scored the highest points is: " << ptr[i].name << endl;
}
}
}