This program is supposed to store inputted grades of 3 students and prints the average. However, if I ask for the average of student B, it prints the average of student A. and Student A's average is 0. I can't seem to find where I went wrong.. Please help e.g. 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;
}
scanf("%c", &j);withscanf(" %c", &j);(An extra space). This will consume any previous\n.