# Answer to Question #5286 in C++ for ghiwa

Question #5286

In gymnastics or diving competitions, each contestant's score is calculated by dropping the lowest and highest scores and then adding the remaining scores. Write a program that allows the user to enter eight judge's score and outputs the points received by the contestant. Format your output with two decimal places.

Expert's answer

# include <iostream.h>

# include <iomanip.h>

void main(){

float a[8], min, max, res;

int i;

for (i=0;i<=7;i++){

& cout<<"Enter a score "<<i+1<<": ";

& cin>>a[i];

}

min = a[0];

max = a[0];

for (i=0;i<=7;i++){

& if (a[i]>max) max = a[i];

& if (a[i]<min) min = a[i];

}

res = min + max;

cout<<setprecision(3)<<res;

}

# include <iomanip.h>

void main(){

float a[8], min, max, res;

int i;

for (i=0;i<=7;i++){

& cout<<"Enter a score "<<i+1<<": ";

& cin>>a[i];

}

min = a[0];

max = a[0];

for (i=0;i<=7;i++){

& if (a[i]>max) max = a[i];

& if (a[i]<min) min = a[i];

}

res = min + max;

cout<<setprecision(3)<<res;

}

## Comments

## Leave a comment