Write a Program: Competition Score
Your goal is to create a program that will determine the average score for an
athlete in a competition. There are 10 judges who each award a score between 0 and 10. The lowest and highest scores are thrown out, and the athlete’s score is the average of the eight remaining scores. The scorecard should have the first and the last name of the athlete on the first line and 10 space-separated numbers between 0 and 10 on the second line. The numbers should have at most 1 digit after the decimal point.
Example Input File:
Mirabella Jones
7.5 8.8 7 8.1 8 9.8 9.3 8.9
Example Output:
First run
ERROR: the scorecard could not be opened
Second run
Insufficient scores
Mirabella Jones is disqualified
Third run
Invalid scores
Mirabella Jones is disqualified
Fourth run
Mirabella Jones's results:
7.5, 8.8, 7.0, 8.1, 8.0, 9.8, 9.3, 8.9
The highest score of 9.8 and the lowest score of 7.0 were dropped
The average score is 8.59
#include<iostream>
#include<string>
using namespace std;
int main()
{
string Fname,Lname;
cout << "Please enter the first name of athlete: ";
cin >> Fname;
cout << "Please enter the last name of athlete: ";
cin >> Fname;
float arr[10];
cout << "Please enter 10 scores of athlete: ";
for (int i = 0; i < 10; i++)
{
cin >> arr[i];
}
float high, low;
high = low = arr[0];
for (int i = 0; i < 10; i++)
{
if (arr[i] > high)
high = arr[i];
if (arr[i] < low)
low = arr[i];
}
float sum = 0;
for (int i = 0; i < 10; i++)
{
if (arr[i] != high&&arr[i] != low)
{
sum+= arr[i];
}
}
cout << "\nThe highest score of " << high << " and the lowest score of " << low << " were dropped ";
cout << "\nThe average score is " << sum / 8;
}
Comments
Leave a comment