题目:运动会5个School参加 统计他们的Totalscore
帮忙改改,谢谢先
#include <stdio.h> #include <stdlib.h> #define TRUE 1 #define FALSE 0 #define MAXNUM 100 typedef enum{A,B,C,D,E} SchoolName; typedef enum{MALE,FEMALE} SexType; struct Component{ SchoolName school; SexType sex; char event; int score; }Component; struct Sum{ int malesum; int femalesum; int totalsum; }; typedef struct Component *PComponent; typedef struct Sum *PSum; PComponent Initialize(); PSum Stat(PComponent p); void Showscore(PSum pl); main() { Component a[10]; Sum b[5]; PComponent p; PSum pl; p=a; pl=b; p=Initialize(); pl=Stat(p); Showscore(pl); getch(); } PComponent Initialize() { int i; PComponent p; for (i=0;i<10;i++) { int a4; char a1,a2,a3; printf("\nPlease input schoolname"); scanf("%c ",&a1); /*printf("\nPlease input sextype"); scanf("%s ",&a2)*/; printf("\nPlease input event name"); scanf("%s ",&a3); printf("\nPlease input score"); scanf("%d ",&a4); (p+i)->school=a1; (p+i)->sex=a2; (p+i)->event=a3; (p+i)->score=a4; } return p; } PSum Stat(PComponent p) { int i; PSum pl; (pl+0)->totalsum=0; (pl+1)->totalsum=0; (pl+2)->totalsum=0; (pl+3)->totalsum=0; (pl+4)->totalsum=0; for (i=0;i<10;i++) { if((p+i)->school=='A') (pl+0)->totalsum+=(p+i)->score; if((p+i)->school=='B') (pl+1)->totalsum+=(p+i)->score; if((p+i)->school=='C') (pl+2)->totalsum+=(p+i)->score; if((p+i)->school=='D') (pl+3)->totalsum+=(p+i)->score; if((p+i)->school=='E') (pl+4)->totalsum+=(p+i)->score; /*else printf("error");*/ } return pl; } void Showscore(PSum pl) { int i; char a[5]={A,B,C,D,E}; for (i=0;i<5;i++) { printf("%c score is %d",a[i],(pl+i)->totalsum); } }