Need help for code

My output is not showing the correct final scores.

double calculateScore(Performer *p, int n){
int Lowest;
int Highest;
for(int i = 0; i<n;i++)
{
Lowest = findLowest(p,i);
Highest = findHighest(p,i);
double total = 0.0;
for (int j =0; j< 5; j++){
total += p[i].scores[j];
}
p[i].final= (total - (Lowest + Highest)) /3 ;
}
}
double findLowest(Performer*p ,int n)
{
int m=p[n].scores[0];
for(int i=1;i<5;i++){
if(m>p[n].scores[i]){
m=p[n].scores[i];
}
}
return m;
}
double findHighest(Performer*p,int n)
{
int m=p[n].scores[0];
for(int i=1;i<5;i++){
if(m<p[n].scores[i]){
m=p[n].scores[i];
}
}
return m;
}

void displayResults(Performer *per, int n)
{
cout << "Display the winners and their scores:\n";
for (int i =0; i < n ; i++){
cout <<"Name: "<<per[i].name;
cout<<setprecision(1)<<fixed;
cout <<". Score: "<< per[i].final;
cout<< endl;
}
}

My output is:
Name: David T. Ng. Score: 9.6
Name: Ann Peterson. Score: 9.6
Name: Andy V. Garcia. Score: 9.3
Name: Dan Nguyen. Score: 8.9
Name: Mary Johnson. Score: 8.9
Name: Lucy A. Smith. Score: 8.8
Name: Sue K. Warren. Score: 8.3
Name: John Lee. Score: 7.8 // the correct score should be 7.5

Can Someone Help me fix my code?



It's calculated here:
p[i].final= (total - (Lowest + Highest)) /3 ;

What are the values of total, Lowest and Highest? Why do you think the calculated score should be 7.5 ?
Garbage in, garbage out. The first 7 scores are correct and the last one is wrong. Perhaps you aren't reading the scores correctly for the last person. Try adding some debugging code to print out all the scores if a person after you read them in.
Garbage in, garbage out. Are you sure that the scores for John Lee are correct? If that's the last person then maybe there's a problem in your code that reads the input. Try printing out each person's scores after you read them to make sure you've read them correctly.
Topic archived. No new replies allowed.