I am working on a programming that uses classes to complete several tasks. I have successfully created a program that reads in the opponent name, home score, and opponent score for a team's season. Now I'm trying to go back and write a method that can be used to output the maximum score achieved by the home team and the opponent they were playing during that game. I know the basic logic that needs to be used in this method: a for loop should be used to navigate the data file, etc. But I can't figure out how to get OpponentName and HomeScore to be for lack of a better word 'grabbed' from the file and then saved as the maximum score that will eventually be outputted. Please Help!!!

I am working on a programming that uses classes to complete several tasks. I have successfully created a program that reads in the opponent name, home score, and opponent score for a team's season. Now I'm trying to go back and write a method that can be used to output the maximum score achieved by the home team and the opponent they were playing during that game. I know the basic logic that needs to be used in this method: a for loop should be used to navigate the data file, etc. But I can't figure out how to get OpponentName and HomeScore to be for lack of a better word 'grabbed' from the file and then saved as the maximum score that will eventually be outputted. Please Help!!!

please post some of your code so that we check it..

please post some of your code so that we check it..

string Team::MaxHomeScore(const string Maximum, const string Filename)
{
ifstream Din;
Din.open(Filename.c_str());
        if(!Din)
        {
                cerr << "Error: That file could not be opened!";
        }
        else
        {
                NumGames = 0;

                Din >> TeamName >> Season;
                cout << endl << "TeamName: " << TeamName <<endl;
                cout << "Season: " << Season <<endl << endl;


                while(Games[NumGames].ReadGameData(Din))
                {
                        for(NumGames = 0; NumGames < MAXGAMES; NumGames++)
                        {
                                if(Games[NumGames] < Maximum)
                                {
                                        //Don't know what syntax should be here!
                                        //This seems very bulky too!
                                }
                        }

                }
        }

        return Maximum;
}

This is what I have for the method in question right now, it's really long and very problematic I feel like! If you need anything else don't hesitate to ask.

I'm not sure I understand why Maximum is a string? If it is you can't use the < with it.

This is one of those things that within that loop you need to have a variable called maximum (an int) and one called maxteam(a string), you can test each incoming score against the maximum, if it's greater set maximum to that current score and maxteam to that current team.

Also, the way you have it set up, the second time through the while loop you'll be at the end of the Games array (since the first time through the while loop, the for loop will run up NumGames). So you should probably keep a different variable for your array count to move that along.

This article has been dead for over six months. Start a new discussion instead.