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;
	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);
		sum1=sum1+stu[i].score1;
		sum2=sum2+stu[i].score2;
		sum3=sum3+stu[i].score3;
	}
	printf("%d %d %d\n",sum1/2,sum2/2,sum3/2);
	int max=stu[0].score1+stu[0].score2+stu[0].score3;
	int index;
	for(int i=0;i<n;i++){
		if(max<=stu[i].score1+stu[i].score2+stu[i].score3){
			max=stu[i].score1+stu[i].score2+stu[i].score3;
			index=i;
		}
	}
	printf("%s %s %d %d %d",stu[index].xuehao,stu[index].name,stu[index].score1,stu[index].score2,stu[index].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:17: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:17: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:17: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:17: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:17: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:18:19: error: request for member 'score1' in something not a structure or union
   sum1=sum1+stu[i].score1;
                   ^
Main.c:19:19: error: request for member 'score2' in something not a structure or union
   sum2=sum2+stu[i].score2;
                   ^
Main.c:20:19: error: request for member 'score3' in something not a structure or union
   sum3=sum3+stu[i].score3;
                   ^
Main.c:23:16: error: request for member 'score1' in something not a structure or union
  int max=stu[0].score1+stu[0].score2+stu[0].score3;
                ^
Main.c:23:30: error: request for member 'score2' in something not a structure or union
  int max=stu[0].score1+stu[0].score2+stu[0].score3;
                              ^
Main.c:23:44: error: request for member 'score3' in something not a structure or union
  int max=stu[0].score1+stu[0].score2+stu[0].score3;
                                            ^
Main.c:26:17: error: request for member 'score1' in something not a structure or union
   if(max<=stu[i].score1+stu[i].score2+stu[i].score3){
                 ^
Main.c:26:31: error: request for member 'score2' in something not a structure or union
   if(max<=stu[i].score1+stu[i].score2+stu[i].score3){
                               ^
Main.c:26:45: error: request for member 'score3' in something not a structure or union
   if(max<=stu[i].score1+stu[i].score2+stu[i].score3){
                                             ^
Main.c:27:14: error: request for member 'score1' in something not a structure or union
    max=stu[i].score1+stu[i].score2+stu[i].score3;
              ^
Main.c:27:28: error: request for member 'score2' in something not a structure or union
    max=stu[i].score1+stu[i].score2+stu[i].score3;
                            ^
Main.c:27:42: error: request for member 'score3' in something not a structure or union
    max=stu[i].score1+stu[i].score2+stu[i].score3;
                                          ^
Main.c:31:36: error: request for member 'xuehao' in something not a structure or union
  printf("%s %s %d %d %d",stu[index].xuehao,stu[index].name,stu[index].score1,stu[index].score2,stu[index].score3);
                                    ^
Main.c:31:54: error: request for member 'name' in something not a structure or union
  printf("%s %s %d %d %d",stu[index].xuehao,stu[index].name,stu[index].score1,stu[index].score2,stu[index].score3);
                                                      ^
Main.c:31:70: error: request for member 'score1' in something not a structure or union
  printf("%s %s %d %d %d",stu[index].xuehao,stu[index].name,stu[index].score1,stu[index].score2,stu[index].score3);
                                                                      ^
Main.c:31:88: error: request for member 'score2' in something not a structure or union
  printf("%s %s %d %d %d",stu[index].xuehao,stu[index].name,stu[index].score1,stu[index].score2,stu[index].score3);
                                                                                        ^
Main.c:31:106: error: request for member 'score3' in something not a structure or union
  printf("%s %s %d %d %d",stu[index].xuehao,stu[index].name,stu[index].score1,stu[index].score2,stu[index].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