Menu
Coddy logo textTech

Student Grade Calculator

Part of the Fundamentals section of Coddy's C# journey — lesson 69 of 69.

challenge icon

Challenge

Easy

Create a method named CalculateAverageGrade that takes an array of integers (representing student grades) as input and returns the average grade as a double. The method should do the following:

  1. Calculate the sum of all grades in the array.
  2. Calculate the average grade by dividing the sum by the number of grades.
  3. Return the average grade
  4. Print the result using the following format: Average grade: [The result].

Try it yourself

using System;

public class Program {
    public static double CalculateAverageGrade(int[] grades) {
        // Write your code here
    }

    public static void Main(string[] args) {
        string text = Console.ReadLine();
        string[] stringArr = text.Split(",");
        int[] studentGrades = new int[stringArr.Length];
        for (int i = 0; i < stringArr.Length; i++) {
           studentGrades[i] = int.Parse(stringArr[i]);
        }
        double averageGrade = CalculateAverageGrade(studentGrades);
        Console.WriteLine($"Average grade: {averageGrade}");
    }
}

All lessons in Fundamentals