C++ exercises and solutions-calculate average score

C++ structure exercise: calculate average score

Step 8: Defining the average(student[] st, int itemcount) method to calculate the average score of a selected student. The method alo starts by asking the user to input the id of the target student. This id is checked to make sure it really exist. 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.

void average(struct student st[], int itemcount)
  string id;
  float avg=0;
  cout<<"Enter students'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;

cout<<"The average score is "<<avg;


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.