Using C language. 1. Assume that each judge’s score is an integer. For each of 3
ID: 3702040 • Letter: U
Question
Using C language.
1. Assume that each judge’s score is an integer. For each of 3 snowboarders (will a loop be helpful with this?), you will be prompting the user to enter the following data on one line using the keyboard: firstname lastname score1 score2 score3 score4 score5 score6 The user should be instructed to separate each data element by at least one space.
2. The first and last name of each snowboarder should be read in and stored in separate arrays named firstnames and lastnames. (If you want to practice more with strings, you may want to explore how to read in and save the whole name at one time and save it in an array called names.)
3. A loop should be used to read in and save scores for each snowboarder into an array of integers named scores. The snowboarder with the highest floating point average of four scores (see description above to understand which four scores) is the winner of the gold medal.
4. Complete the Problem Description, Input, Output, and Assumptions sections of a Lab Report. Decide on the tasks necessary for applying the rules to determine the gold medal winner. In the Algorithm section of your lab report, draw a decomposition diagram showing an overview of the main tasks required.
5. Below the decomposition diagram in your lab report, list the sequence in which tasks should be executed. This is not a detailed algorithm, simply a high-level sequence.
6. Include in the Example section of your lab report an example worked by hand, using the following sample data below (with a pretend mix of male/female USA athletes). Name Six judges’ scores Avg (excluding min and max) Sean White 96 98 88 99 98 100 average 97.75 Chloe Kim 92 99 100 98 99 97 (average 98.25) Ben Ferguson 90 95 91 85 94 88 average 90.75
7. Write the code to determine the average score for each competitor. For each snowboarder, display a message stating the person’s whole name and the average of that snowboarder’s four scores. This will help verify that your program works correctly for each person.
8. Finally, write the code to determine the gold medal-winning score. Display a message stating the winner’s whole name and average score.
9. Use the sample data to test your program and verify that actual results match expected results. In the Test Plan section of your lab report, document the first test case using the sample data, and also a screenshot of the execution results obtained using the sample data.
10. Next, construct a test case using test data of your own, and execute your program to verify that actual results match expected results. You may use your own choice of names (perhaps you and your friends?) and scores. Document your test data in the in the Test Plan section of your lab report, and include a screenshot of the execution results using your test data.
This is what I got so far. Please help.
#include <stdio.h>
#include <string.h>
int main()
{
/*Determine Values*/
char firstName [20];
char lastName [20];
int scores[6];
int i,maxScore,minScore,indexMax;
/*Prompt and read in data for one snow border */
printf("enter firstName lastName and 6 scores: ");
scanf("%s %s", &firstName, &lastName);
printf("the name was : %s %s ", firstName, lastName);
for(i=0;i<6;i++){
scanf(" %d",&scores [i]);
printf("the scores entered was: %d ", scores[i]);
}
/*determine maximum score*/
maxScore=scores[0];
for(i=0; i<6;i++)
{
if(scores[i] > maxScore)
maxScore= scores[i] ;
}
printf("the Hihest score is : %d ",maxScore);
/* determine the minimum score*/
minScore=scores[0];
for(i=0; i<6;i++)
{
if(scores[i] < minScore)
minScore= scores[i] ;
}
printf("the minimal score is : %d ",minScore);
/*sum up all 6 scores in an array*/
int total =0;
for(i=0;i<6;i++)
{
total= total +scores[i];
}
printf("the total is : %d", total);
/* subtrac max and min for sum*/
/* compute the adjusted average of remaingn four scores*/
return 0;
}
Explanation / Answer
Yes you can use a for loop. See the code below. All you have to do is to make is a 2 dimensional array instead of a 1 dimensional array. I have changed your code a little bit and have commented at appropriate places. Just copy the code and run on your IDE. Have fun.
#include <stdio.h>
#include <string.h>
int main()
{
int total[3];
float adj_total[3];
float adj_avg[3];
int j;
char firstName [3][20];//
char lastName [3][20];
int scores[3][6];
/*Determine Values*/
for (j=0;j<3;j++){
int i,maxScore,minScore,indexMax;
char firstName [3][20];//
char lastName [3][20];
/*Prompt and read in data for one snow border */
printf("enter firstName lastName and 6 scores of person %d",j+1," ");
scanf("%s %s", firstName[j], lastName[j]);
printf("the name was : %s %s ", firstName[j], lastName[j]);
for(i=0;i<6;i++){
scanf(" %d",&scores [j][i]);
printf("the scores entered was: %d ", scores[j][i]);
}
/*determine maximum score*/
maxScore=scores[j][0];
for(i=0; i<6;i++)
{
if(scores[j][i] > maxScore)
maxScore= scores[j][i] ;
}
printf("the Highest score is : %d ",maxScore);
/* determine the minimum score*/
minScore=scores[j][0];
for(i=0; i<6;i++)
{
if(scores[j][i] < minScore)
minScore= scores[j][i] ;
}
printf("the minimal score is : %d ",minScore);
/*sum up all 6 scores in an array*/
total[j] =0;
for(i=0;i<6;i++)
{
total[j]= total[j] +scores[j][i];
}
printf("the total is : %d ", total[j]);
/* subtract max and min from sum*/
adj_total[j]= total[j]-maxScore-minScore;
printf("the adjusted total is : %f ", adj_total[j]);
/* compute the adjusted average of remaingn four scores*/
adj_avg[j]= adj_total[j]/4;
printf("the adjusted average is : %f ", adj_avg[j]);
}
// now finding the index of the highest adjusted average
int k = 0;
int m;
float max = adj_avg[k];
for (m = 0; m < 3; ++m)
{
if (adj_avg[m] > max)
{
max = (int)adj_avg[m];
k = m;
}
}
printf("Person %d",k+1," is the winner"," ");// the person with highest adj average is the winner
printf("The winner is : %s %s ", firstName[k+1], lastName[k+1]);
return 0;
}
Edited code:
#include <stdio.h>
#include <string.h>
int main()
{
int total[3];
float adj_total[3];
float adj_avg[3];
int j;
char *firstName [3][3];//
char *lastName [3][3];
int scores[3][6];
/*Determine Values*/
for (j=0;j<3;j++){
int i,maxScore,minScore,indexMax;
/*Prompt and read in data for one snow border */
printf("enter firstName lastName and 6 scores of person %d",j+1," ");
scanf("%s %s", firstName[j], lastName[j]);
printf("the name was : %s %s ", firstName[j], lastName[j]);
for(i=0;i<6;i++){
scanf(" %d",&scores [j][i]);
printf("the scores entered was: %d ", scores[j][i]);
}
/*determine maximum score*/
maxScore=scores[j][0];
for(i=0; i<6;i++)
{
if(scores[j][i] > maxScore)
maxScore= scores[j][i] ;
}
printf("the Highest score is : %d ",maxScore);
/* determine the minimum score*/
minScore=scores[j][0];
for(i=0; i<6;i++)
{
if(scores[j][i] < minScore)
minScore= scores[j][i] ;
}
printf("the minimal score is : %d ",minScore);
/*sum up all 6 scores in an array*/
total[j] =0;
for(i=0;i<6;i++)
{
total[j]= total[j] +scores[j][i];
}
printf("the total is : %d ", total[j]);
/* subtract max and min from sum*/
adj_total[j]= total[j]-maxScore-minScore;
printf("the adjusted total is : %f ", adj_total[j]);
/* compute the adjusted average of remaingn four scores*/
adj_avg[j]= adj_total[j]/4;
printf("the adjusted average is : %f ", adj_avg[j]);
}
// now finding the index of the highest adjusted average
int k = 0;
int m;
float max = adj_avg[k];
for (m = 0; m < 3; ++m)
{
if (adj_avg[m] > max)
{
max = (int)adj_avg[m];
k = m;
}
}
printf("Person %d is the winner ",k+1);// the person with highest adj average is the winner
printf("The winner is : %s %s ", firstName[k], lastName[k]);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.