Student Grade Calculator
Part of the Fundamentals section of Coddy's C# journey — lesson 69 of 69.
Challenge
EasyCreate 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:
- Calculate the sum of all grades in the array.
- Calculate the average grade by dividing the sum by the number of grades.
- Return the average grade
- 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
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic Shortcuts5Operators Part 2
Comparison OperatorsLogical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3