我有以下代码:
#define MIDTERM_PERCENTAGE 40
#define FINAL_PERCENTAGE 60
#define ARRAY_LENGTH(array) (sizeof((array))/sizeof((array)[0]))
struct student
{
char name[20];
int midterm;
int final;
int grade;
}
int calcGrade(struct student s) {
int midterm = (s.midterm * MIDTERM_PERCENTAGE)/100;
int final = (s.final * FINAL_PERCENTAGE)/100;
int grade = midterm + final;
return grade;
}
我收到这些错误:
student.c:13: two or more data types in declaration of `calcGrade'
student.c: In function `calcGrade':
student.c:17: incompatible types in return
我也有一个具有以下声明的头文件:
int calcGrade(struct student s);
但是,我没有看到我的错误。我认为这可能是我的部门的问题,但由于它在设置 Grade=midterm+final 时没有给我任何错误,我不明白为什么我的返回类型有问题。