In: Computer Science
C Programming
Debug -> error: expected expression before 'score'
typedef enum LetterGrade {
A = 4,
B = 3,
C = 2,
D = 1,
F = 0
} score;
score getLetterGradeFromAverage(const double avg)
{
if (avg >= 90)
return
score::A;
// error here
else if (avg >= 80)
return
score::B; //
error here
else if (avg >= 70)
return
score::C; // error
here
else if (avg >= 60)
return
score::D; // error
here
else
return
score::F; //
error here
}
/*
In standard c, things to the left of "::" MUST BE STRUCT, enums don't count.
*/
#include<stdio.h>
typedef enum LetterGrade {
A = 4,
B = 3,
C = 2,
D = 1,
F = 0
}score ;
score getLetterGradeFromAverage(const double avg)
{
if (avg >= 90)
return A;
else if (avg >= 80)
return B;
else if (avg >= 70)
return C;
else if (avg >= 60)
return D;
else
return F;
}
int main(){
int avg = 90;
if(A == getLetterGradeFromAverage(avg)){
printf("A");
}else if(B == getLetterGradeFromAverage(avg)){
printf("B");
}else if(C == getLetterGradeFromAverage(avg)){
printf("C");
}else if(D == getLetterGradeFromAverage(avg)){
printf("D");
}else if(F == getLetterGradeFromAverage(avg)){
printf("F");
}
}