using C language only In the sport of diving, seven judges award a score between
ID: 3827412 • Letter: U
Question
using C language only
In the sport of diving, seven judges award a score between 0 and 10, where each score may be a floating point value. The highest and the lowest scores are thrown out and the remaining scores are added together. The sum is then multiplied by the degree of difficulty for that dive. Degree of difficulty ranges from 1.1 to 3.9 points. The total is then multiplied by 0.6 to determine the diver's score. Write a function called getData() that asks the user to enter the diver's name the 7 judge's scores which are loaded into an array, and the degree of difficulty. Write another function called calcScore() that returns the diver's score. You calculate the score by removing the highest score and the lowest and calculates the sum of the remaining score. Multiply the sum by the degree of difficulty. Next multiply this by 0.6 to calculate the diver's score. Write a final function called displayData() that will display the diver's name, all of the judges scores, the degree of difficulty, and the diver's final score. You must validate both the degree of difficulty and the judges' scores. Ask if you would like to calculate the score for another diver. Diver's name: Susie Nerdsy Judges scores: Degree of difficulty: 2.30 Final score: 40.71 Would you like to calculate for another diver (Y/N)? nExplanation / Answer
#include <stdio.h>
#include <string.h>
/*Global variables*/
char diverName[50];
float judgeScore[7];
float degreeDifficulty;
float diverScore;
int i;
/*function declarations*/
void getData(void);
float calcScore(void);
void displayData(void);
void getData()
{
//~ fseek(stdin,0,SEEK_END);
strcpy(diverName, "");//initially nothing in name
printf("Enter the Divir's Name: ");//enter name with no spaces
scanf("%s",diverName);
for(i=0;i<7;i++)
{
reenter_score:
printf("Enter judge %d score: ",i);
scanf("%f",&judgeScore[i]);
//validation for judges scores
if(!(judgeScore[i] >=0.0 && judgeScore[i] <=10.00))
{
printf("Please enter valid float value between 0 to 10 ");
goto reenter_score;
}
}
reenter_dod:
printf("Enter degree of difficulty ");
scanf("%f",°reeDifficulty);
//validation for degree of Difficulty
if(!(degreeDifficulty>=1.1 && degreeDifficulty <= 3.9))
{
printf("Please enter valid float value between 1.1 to 3.9 ");
goto reenter_dod;
}
}
float calcScore()
{
float retDiverScore;
float sumJudgeScore=0.0;
/* Supposes the first element as maximum and minimum */
float highScore=judgeScore[0];
float lowScore=judgeScore[0];
/*Finds maximum and minimum in all array elements*/
for(i=0;i<7;i++)
{
/* If current element of array is greater than max */
if(judgeScore[i]>highScore)
{
highScore = judgeScore[i];
}
/* If current element of array is smaller than min */
if(judgeScore[i]<lowScore)
{
lowScore = judgeScore[i];
}
sumJudgeScore=sumJudgeScore+judgeScore[i];
}
sumJudgeScore=sumJudgeScore-highScore-lowScore;//excluding min and max
sumJudgeScore=sumJudgeScore*degreeDifficulty;//sum x degreeof dificulty
retDiverScore=sumJudgeScore*0.6;//divir's score
return retDiverScore;
}
void displayData()
{
printf("Entered the Divir's Name: %s ",diverName);
printf("Judges Scores: ");
for(i=0;i<7;i++)
{
printf(" %f ",judgeScore[i]);
}
printf("Degree of Dificulty: %f ",degreeDifficulty);
printf("Final Score:%f ",diverScore);
}
int main()
{
int option;
repet:
getData();
diverScore=calcScore();
displayData();
printf("Would you like to calculate for another driver(1/0)?: '1' for yes & '0' for No ");
scanf("%d",&option);
if(option==1)
{
goto repet;
}
if(option == 0)
{
return 0;
}
else
{
printf("invalid option ");
return 0;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.