0

// 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;
}
2
Contributors
8
Replies
9
Views
4 Years
Discussion Span
Last Post by WaltP
Featured Replies
  • 1
    WaltP 2,905   4 Years Ago

    And what happens when you input **EXACTLY** the same input? ---- this is like pulling teeth Read More

0

What is wrong? Please give details.

What actually is displayed? (actual text) And what's wrong with this?
What do you want displayed? (actual text, variable names, etc)
Examples help greatly.

0

The last function that displays the highest score, I actually want it to display the name of the highest scorers

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;
}

highest scorers

0

I repeat

What actually is displayed? (actual text) And what's wrong with this?
What do you want displayed? (actual text, variable names, etc)
Examples help greatly.

Was I unclear?

Edited by WaltP

0

Nothing is being displayed for the current code that I have for the HighestScore function

Example:
You

You will now be asked to enter the name
uniform number, and points earned for each player.
___________________________________________________
Enter Player's Name: Dre
Enter Player's Uniform Number: 5
Enter Player's Points: 4

Enter Player's Name: Day
Enter Player's Uniform Number: 3
Enter Player's Points: 2

Players Score Summary

__________________________________________
Name               Number            Score
__________________________________________
Dre                 5              4
Day                 3              2
The total score is: 6
The highest scorers are:     &    
logout

[Process completed]
0

And you still are.

The questions, one at a time:

What actually is displayed? (actual text)

Yes, you finally showed what was displayed.

And what's wrong with this?

I still don't really know, I have to guess.

What do you want displayed? (actual text, variable names, etc)

Don't see anything that shows what should have been displayed so I can't compare what your program should show vs what it did show.

Still don't know what variables you wanted to display -- again, I have to guess.

-------------

When answering questions, read each question one at a time and ask yourself "did I answer that question so they have the answer they asked for?"

Based on the input, you know what the output should be. We don't. So show us.

Edited by WaltP

0

Im sorry, This is a sample output im trying to emulate

PLAYER #1
---------
Player name: Susie Queue
Player's number: 12
Points scored: 4

PLAYER #2
---------
Player name: Fred Funk
Player's number: -92
Please enter a number that is 0 or greater: -100
Please enter a number that is 0 or greater: 45
Points scored: 2

PLAYER #3
---------
Player name: Janie Jane
Player's number: 76
Points scored: -1
Please enter a number that is 0 or greater: 4

NAME               NUMBER    POINTS SCORED
==========================================
Susie Queue         12        4
Fred Funk           45        2
Janie Jane          76        4

TOTAL POINTS EARNED BY ENTIRE TEAM: 10

PLAYERS(S) WHO SCORED THE MAXIMUM POINTS:

Susie Queue
Janie Jane

Execution Terminated.
Press any key to continue
1

And what happens when you input EXACTLY the same input?

----

this is like pulling teeth

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.