I am trying to make one or two classes that input the opponent name and the home score from a data file. I already have a function that fills an array and prints that information to screen. Now I need to be able to filter through the data and find the highest home score within the games and output the information mentioned above. I'm not sure how to do this in code though; please help! Thank you!
traverse the array using a for loop, and do a comparison inside this loop.
for ( initializer ; length ; increment )
1 2 3 4
for ( int i = 0; i < array_size ; i++ )
{
// TODO: functions in here.
}
edit: i guess it depends somewhat on data types. But basically you can have a variable called score_max, initialize score max to array[0], and then if ( array[i] > score_max ) { score_max = array[i] }
This is the method I had written for this problem. OpponentName and HomeScore are private variables in game.cpp (the code below is from team.cpp) and I know I probably shouldn't use them; instead, should I use a get method? And how do I output that information?