C# exercises solution-average score in list

C# structure: student records application

Average score

Step8: 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.

static void average(student[] st, int itemcount)
string id;
float avg=0;
Console.Write("Enter students'ID:");
id = Console.ReadLine();
int index = search(st, id.ToString(),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;

Console.WriteLine("The average score is {0}.", 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.