I'm working on creating a function for a larger program that will take a letter grade that is entered and stored in an array elsewhere in the program and then assign a grade point to that letter grade (ie. A = 4.0, B = 3.0, etc.), which will later be used in another function to calculate total GPA based on course hours that have been stored in another array.
I've chosen to use a switch statement because I'm familiar with them from previous programming I've done, but I'm open to a better method of accomplishing this task if possible. The current error I'm getting is "switch statement not integral".
float GradePoints(char grades[])
{
float points = 0.0;
switch (grades[])
{
case 'A':
points = 4.0;
break;
case 'B':
points = 3.0;
break;
case 'C':
points = 2.0;
break;
case 'D':
points = 1.0;
break;
case 'F':
points = 0.0;
break;
}
return points;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…