我对C#非常陌生,并试图开发GPA计算器。它有10个文本框和另一个文本框来输入课程数。当用户输入所有10个等级时它工作正常,但当用户输入少于10个等级时,它会显示错误 - '您的应用程序中出现了未处理的异常'
代码的一部分 -
TextBox[] boxes = { txbCourse1, txbCourse2, txbCourse3, txbCourse4, txbCourse5, txbCourse6, txbCourse7, txbCourse8, txbCourse9, txbCourse10 };
//use of a loop to go over the array and find GPA for each course
for (int i = 0; i < 10; i++)
{
input = Convert.ToChar(boxes[i].Text);
if (input == 'A' || input == 'a')
GPA = GRA;
if (input == 'B' || input == 'b')
GPA = GRB;
if (input == 'C' || input == 'c')
GPA = GRC;
if (input == 'D' || input == 'd')
GPA = GRD;
if (input == 'E' || input == 'e')
GPA = GRE;
if (input == 'F' || input == 'f')
GPA = GRF;
total += GPA;
}
//output to the user (cumulative GPA)
cumGPA = Math.Round(total / number,2);
lblGPA.Text = "The Cumulative GPA: " + cumGPA;
}