This is all in C My question is can you change the code i ha

This is all in C

My question is can you change the code i have to just do the following

Write a function that will display the “overall score” of all 10 students in a single column.

#include <stdio.h>
struct score
{
float HW;
float Exam1;
float Exam2;
float Exam3;
};
struct student
{
int id;
int YearofSchool;
struct score course_scores;
};
int main(void)
{
struct student s[10]; //Array of structures for 10 students
int id[10] ={1,2,3,4,5,6,7,8,9,10};
int yearofSchool[10] ={4,3,2,3,4,1,2,3,4,2};
int hw[10] = {78,80,78,72,94,67,82,75,52,76};
int exam1[10] = {67,85,76,95,84,76,72,85,86,79};
int exam2[10] = {90,86,88,77,96,76,78,72,81,91};
int exam3[10] = { 80,75,82,76,83,79,84,77,98,74};
int courseAverage[10];
int overall_score[10];
int i;
int AverageOverallScore =0;
  
for(i=0;i<10;i++) //initialization of arrays of structures using arrays
{
s[i].id =id[i];
s[i].YearofSchool =yearofSchool[i];
s[i].course_scores.HW = hw[i];
s[i].course_scores.Exam1 = exam1[i];
s[i].course_scores.Exam2 = exam2[i];
s[i].course_scores.Exam3 = exam3[i];
  
}
  
for(i=0;i<10;i++) //calculate overall score for each student
{
overall_score[i] = s[i].course_scores.HW*0.2 + s[i].course_scores.Exam1*0.25 +s[i].course_scores.Exam2*0.25 +s[i].course_scores.Exam3*0.3;
printf(\"\ Overall score of student %d = %d\",i+1,overall_score[i]);
}
  
for(i=0;i<10;i++) //calculate average score for exams
{
courseAverage[i] = (s[i].course_scores.Exam1+s[i].course_scores.Exam2 +s[i].course_scores.Exam3)/3;
printf(\"\ Course Average of Student %d in Exam1,Exam2 and Exam3 =%d\",i+1,courseAverage[i]);
}
  
for(i=0;i<10;i++)
{
AverageOverallScore = AverageOverallScore +overall_score[i]; //calculate overall average score
}
  
printf(\"\ Average Overall score = %d\",AverageOverallScore/10);
return 0;
}

Solution

#include <stdio.h>

void displayOverallScore();// declaration of a function
struct score
{
float HW;
float Exam1;
float Exam2;
float Exam3;
};
struct student
{
int id;
int YearofSchool;
struct score course_scores;
};
int main(void)
{
struct student s[10]; //Array of structures for 10 students
int id[10] ={1,2,3,4,5,6,7,8,9,10};
int yearofSchool[10] ={4,3,2,3,4,1,2,3,4,2};
int hw[10] = {78,80,78,72,94,67,82,75,52,76};
int exam1[10] = {67,85,76,95,84,76,72,85,86,79};
int exam2[10] = {90,86,88,77,96,76,78,72,81,91};
int exam3[10] = { 80,75,82,76,83,79,84,77,98,74};
int courseAverage[10];
int overall_score[10];
int i;
int AverageOverallScore =0;

for(i=0;i<10;i++) //initialization of arrays of structures using arrays
{
s[i].id =id[i];
s[i].YearofSchool =yearofSchool[i];
s[i].course_scores.HW = hw[i];
s[i].course_scores.Exam1 = exam1[i];
s[i].course_scores.Exam2 = exam2[i];
s[i].course_scores.Exam3 = exam3[i];
  
}

  
for(i=0;i<10;i++) //calculate overall score for each student
{
overall_score[i] = s[i].course_scores.HW*0.2 + s[i].course_scores.Exam1*0.25 +s[i].course_scores.Exam2*0.25 +s[i].course_scores.Exam3*0.3;
// printf(\"\ Overall score of student %d = %d\",i+1,overall_score[i]);
}
  
for(i=0;i<10;i++) //calculate average score for exams
{
courseAverage[i] = (s[i].course_scores.Exam1+s[i].course_scores.Exam2 +s[i].course_scores.Exam3)/3;
printf(\"\ Course Average of Student %d in Exam1,Exam2 and Exam3 =%d\",i+1,courseAverage[i]);
}
displayOverallScore(overall_score);// calling function to display overall score of 10 students in a single coloumn
for(i=0;i<10;i++)
{
AverageOverallScore = AverageOverallScore +overall_score[i]; //calculate overall average score
}
  
printf(\"\ Average Overall score = %d\",AverageOverallScore/10);
return 0;
}
void displayOverallScore(int a[]){// function to display overall score of 10 students in a single coloumn
printf(\"\ Overall score of 10 students\");

for(int i=0;i<10;i++) //calculate overall score for each student
{

printf(\"\ student%d = %d\",i+1,a[i]);
}


}

This is all in C My question is can you change the code i have to just do the following Write a function that will display the “overall score” of all 10 student
This is all in C My question is can you change the code i have to just do the following Write a function that will display the “overall score” of all 10 student
This is all in C My question is can you change the code i have to just do the following Write a function that will display the “overall score” of all 10 student

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site