C exercises and solutions: calculate average score


C structure: calculate average score

Step 8: Defining the average(student[] st, int itemcount) function to calculate the average score of a selected student. The function also starts by asking the user to input the id of the target student. This id is checked to make sure it really exists. The average score can be calculated by dividing the sum of quizz1 score, quizz2 score, assignment score, mid-term score, and final score by 5.

//function to calculate the average score of a student
void average(student st[], int itemcount)
{
char id[10];
float avg=0;
printf("Enter students'ID:");
scanf("%s",&id);
int index = search(st, id,itemcount);
if (index != -1 && itemcount>0)
{
st[index].total = st[index].quizz1 + st[index].quizz2 + st[index].assigment + st[index].midterm + st[index].final;
avg = st[index].total /5;
}

printf("The average score is %f.",avg);
}




Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.