It keeps telling me there is an error on line 22 when I run the program. Does anyone see the problem. My goal was to create a jagged array where the first block had 3 grades, the second block had 2 grades, and the third block had 4 grades.
using System;
public class Grades
{
public static void Main(string [] args)
{
int[][] grades;
grades = new int[3][];
grades[0] = new int[3];
grades[1] = new int[2];
grades[2] = new int[4];
for (int i = 0; i < grades.GetLength(0); i++)
{
Console.WriteLine("Please input grade for first course followed by enter: ");
grades[0][i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine();
for (int i = 0; i < grades.GetLength(1); i++)
{
Console.WriteLine("Please input grade for second course followed by enter: ");
grades[1][i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < grades.GetLength(2); i++)
{
Console.WriteLine("Please input grade for third course followed by enter: ");
grades[2][i] = Convert.ToInt32(Console.ReadLine());
}
Console.Write("The grades for the first course are: {0}, {1}, and {2}", grades[0][0], grades[0][1], grades[0][2]);
Console.WriteLine();
Console.Write("The grades for the second course are: {0} and {1}", grades[1][0], grades[1][1], grades[1][2]);
Console.WriteLine();
Console.Write("The grades for the third course are: {0}, {1}, {2}, and {3}", grades[2][0], grades[2][1], grades[2][2], grades[2][3]);
Console.ReadKey();
} // end Main
} // end class Grades