View Code of Problem 82

#include<stdio.h>
struct student{
	char xuehao[5];
	char name[10];
	int score1;
	int score2;
	int score3;
};
int main(){
	int n;
	scanf("%d",&n);
	student stu[n];
	int sum1=0;
	int sum2=0;
	int sum3=0;
	int sum[10];
	int max=0;
	for(int i=0;i<n;i++){
		scanf("%s%s%d%d%d",&stu[i].xuehao,&stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3);
		
	}
	for(int i=0;i<n;i++){
		sum1=sum1+stu[i].score1;
		sum2=sum2+stu[i].score2;
		sum3=sum3+stu[i].score3;
		sum[i]=stu[i].score3+stu[i].score2+stu[i].score1;
		if(sum[i]>sum[max]){
			max=i;
		}
	}
	printf("%d %d %d\n",sum1/2,sum2/2,sum3/2);

	printf("%s %s %d %d %d",stu[max].xuehao,stu[max].name,stu[max].score1,stu[max].score2,stu[max].score3);
	
	return 0;
}
/*
Main.c: In function 'main':
Main.c:12:2: error: unknown type name 'student'; use 'struct' keyword to refer to the type
  student stu[n];
  ^~~~~~~
  struct 
Main.c:19:29: error: request for member 'xuehao' in something not a structure or union
   scanf("%s%s%d%d%d",&stu[i].xuehao,&stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3);
                             ^
Main.c:19:44: error: request for member 'name' in something not a structure or union
   scanf("%s%s%d%d%d",&stu[i].xuehao,&stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3);
                                            ^
Main.c:19:57: error: request for member 'score1' in something not a structure or union
   scanf("%s%s%d%d%d",&stu[i].xuehao,&stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3);
                                                         ^
Main.c:19:72: error: request for member 'score2' in something not a structure or union
   scanf("%s%s%d%d%d",&stu[i].xuehao,&stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3);
                                                                        ^
Main.c:19:87: error: request for member 'score3' in something not a structure or union
   scanf("%s%s%d%d%d",&stu[i].xuehao,&stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3);
                                                                                       ^
Main.c:23:19: error: request for member 'score1' in something not a structure or union
   sum1=sum1+stu[i].score1;
                   ^
Main.c:24:19: error: request for member 'score2' in something not a structure or union
   sum2=sum2+stu[i].score2;
                   ^
Main.c:25:19: error: request for member 'score3' in something not a structure or union
   sum3=sum3+stu[i].score3;
                   ^
Main.c:26:16: error: request for member 'score3' in something not a structure or union
   sum[i]=stu[i].score3+stu[i].score2+stu[i].score1;
                ^
Main.c:26:30: error: request for member 'score2' in something not a structure or union
   sum[i]=stu[i].score3+stu[i].score2+stu[i].score1;
                              ^
Main.c:26:44: error: request for member 'score1' in something not a structure or union
   sum[i]=stu[i].score3+stu[i].score2+stu[i].score1;
                                            ^
Main.c:33:34: error: request for member 'xuehao' in something not a structure or union
  printf("%s %s %d %d %d",stu[max].xuehao,stu[max].name,stu[max].score1,stu[max].score2,stu[max].score3);
                                  ^
Main.c:33:50: error: request for member 'name' in something not a structure or union
  printf("%s %s %d %d %d",stu[max].xuehao,stu[max].name,stu[max].score1,stu[max].score2,stu[max].score3);
                                                  ^
Main.c:33:64: error: request for member 'score1' in something not a structure or union
  printf("%s %s %d %d %d",stu[max].xuehao,stu[max].name,stu[max].score1,stu[max].score2,stu[max].score3);
                                                                ^
Main.c:33:80: error: request for member 'score2' in something not a structure or union
  printf("%s %s %d %d %d",stu[max].xuehao,stu[max].name,stu[max].score1,stu[max].score2,stu[max].score3);
                                                                                ^
Main.c:33:96: error: request for member 'score3' in something not a structure or union
  printf("%s %s %d %d %d",stu[max].xuehao,stu[max].name,stu[max].score1,stu[max].score2,stu[max].score3);
                                                                                                ^
Main.c:12:10: warning: variable 'stu' set but not used [-Wunused-but-set-variable]
  student stu[n];
          ^~~
*/

Double click to view unformatted code.


Back to problem 82