该程序应该存储输入的 3 名学生的成绩并打印平均成绩。但是,如果我要求学生 B 的平均值,它会打印学生 A 的平均值。学生 A 的平均值为 0。我似乎找不到哪里出错了。请帮助,例如 Student_A = {7,7, 7},Student_B = {8,8,8};ave(Student_B) = 7
#include<stdio.h>
int i;
char j;
int student_A[4];
int student_B[4];
int student_C[4];
float grade_input(int student[]);
float ave(int student[]);
main(){
printf("For Student A:\n");
grade_input(&student_A[4]);
printf("For Student B:\n");
grade_input(&student_B[4]);
printf("For Student C:\n");
grade_input(&student_C[4]);
do{
printf("Whose average grade do you want to see, a ,b ,c? ");
getchar();
scanf("%c", &j);
if(j=='a'){
printf("%.2f\n", ave(student_A));
}
if(j=='b'){
printf("%.2f\n", ave(student_B));
}
if(j=='c'){
printf("%.2f\n", ave(student_C));
}
}while(j=='a' || j=='b' || j=='c');
}
float grade_input(int student[]){
int i;
for(i=0; i<3; i++){
printf("Enter grade %d: ", i+1);
scanf("%d", &student[i]);
}
}
float ave(int student[]){
return (student[0] + student[1] + student[2])/3.0;
}