In: Computer Science
In the sport of diving, seven judges award a score between 0 and 10, where each score may be a floating-value. The highest and lowest scores are thrown out and the remaining scores are added together. The sum is then multiplied by the degree of difficulty for that drive. The degree of difficulty ranges from 1.2 to 3.8 points. The total is then multiplied by 0.6 to determine the diver’s score.
Write a program that inputs a degree of difficulty and then input seven judges’ scores using a loop and outputs the overall score for that dive.
You are required to check whether a judge’s score is indeed between 0 and 10. You also have to check whether the difficulty is between 1.2 and 3.8. When the user enters a number that is not in the range, ask the user to enter it again.
Example: To ask the user to enter a score between 0 and 100
do{
cout<<”Enter a number between 0 and 100”;
cin>>score;
}while(score<0 || score>100);
Hint: You should use a loop to find total score, highest score, and lowest score. You then subtract total from highest and lowest. Multiply result by difficulty and 0.6 to get the final score. If the user enters difficulty as 2 and seven judges give score as 1, 2, 3, 4, 5, 6, and 7. Then the final score should be 24
do it in C++
#include <iostream>
using namespace std;
int main(){
float scores[7];
float difficulty;
cout << "Enter 7 Judge scores" <<endl;
// read 7 judge scores in range 0 and 10
for(int i=0; i<7 ;i++){
while(true){
cout <<"Enter Judge "<< (i+1)<<" scores between 0 to 10 : ";
cin >> scores[i];
if( scores[i] >= 0 && scores[i] <= 10 ){
break;
}
cout << "Enter valid score" << endl;
}
}
// read difficulty scores in range 1. and 3.8
while(true){
cout << "Enter degree of difficulty : ";
cin >> difficulty;
if( difficulty >= 1.2 && difficulty <=3.8 ){
break;
}
}
float minScore = scores[0];
float maxScore = scores[0];
float total = 0;
// finding lowest, highest and total scores
for(int i=0; i<7 ;i++){
total += scores[i];
if( minScore > scores[i] ){
minScore = scores[i];
}
if( maxScore < scores[i] ){
maxScore = scores[i];
}
}
float temp = total - (minScore + maxScore);
// calculating final score
float finalScore = temp * difficulty * 0.6;
cout << "Final Score : " << finalScore;
return 1;
}
Code
Output