hello! i wrote this code, but i am having some issue with fiding the higiest value stored in p[i].points_scored corresponding with the player who scored it.
but I cant seem to find any answer online regarding how to point to the array in the structure in regards of the previously specified. The player who scored the highest.
help?
//find the player with the highest score
int highscore(Player p[],int players){
int max = -1;
for(int i = 0; i < players; i++){
if(p[i].points_scored > max){
max = i;
}
}
return max;
}
Than, this will return where (into the array of players) is the one with the biggest score. So, to call it you should do this:
1 2 3 4 5 6 7 8
// Get the position of the player scoring the most points.
int max_score = highscore(p, 5);
cout<<"The player who scored the most points is: "
<< p[max_score].name << endl; // you can display its number too
return 0;
Also, I assumed that there is no one with a negative score. If it is possible for that condition to happen, just change the max value into the function with another sentinel value.