大家帮忙看看这段程序的问题~~·谢了(急!)
还没写完 但已经有问题了 5555555~~·~~
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#define P() printf(" \n")
#define SIZE 2
struct student
{
char name[10];
int num;
char sex;
int age;
int chinese;
int math;
int english;
int computer;
}s[SIZE];
void save()
{
int i;
FILE *fp;
printf("please input SIZE students informations:\n");
printf("the information include:Name Number Sex Age Chinese Math English Computer\n");
for(i=0;i<SIZE;i++)
scanf("%s%d%c%d%d%d%d%d",s[i].name,&s[i].num,&s[i].sex,&s[i].age,&s[i].chinese,&s[i].math,&s[i].english,&s[i].computer);
if((fp=fopen("student_list","wb"))==NULL)
{
printf("cannot open file\n");
return;
}
for(i=0;i<SIZE;i++)
if(fwrite(&s[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
void read_in()
{
int i;
FILE *fp;
char infile[15];
fp=fopen("student_list","rb");
for(i=0;i<SIZE;i++)
fread(&s[i],sizeof(struct student),1,fp);
fclose(fp);
}
void menu()
{
clrscr();
P();
printf(" ===============================================================\n");
printf(" \n");
printf(" Welcome to the student score management system \n");
printf(" \n");
printf(" ****---****----****----****________****----****----****----****\n");
printf(" | | | made by : |\n");
printf(" | | MENU | Wang Deng Hong |\n");
printf(" |--------------------------________---------------------------|\n");
printf(" | |\n");
printf(" | |\n");
printf(" | 1> Search 2> Input record 3> Modify record |\n");
printf(" | |\n");
printf(" | |\n");
printf(" | 4> Average score 5> Rankings 6> Quit |\n");
printf(" | |\n");
printf(" | |\n");
printf(" ***************************************************************\n");
printf(" \n");
printf(" Please input your choice(1~6): ");
}
void menu2()
{
clrscr();
P();
printf(" --------------------------Select Menu-------------------------\n");
P();
printf(" 1> Search on name 2> Search on number \n");
P();
printf(" 3> Search on score 4> Search on sex \n");
P();
printf(" 5> Return the main menu \n");
P();
printf(" ---------------------------------------------------------------\n");
P();
printf(" please choice(1~5): ");
}
void menu2_s()
{
clrscr();
P();
printf(" --------------------------Select Menu-------------------------\n");
P();
printf(" 1> Search Chinese score 2> Search Math score \n");
P();
printf(" 3> Search English score 4> Search Computer score \n");
P();
printf(" 5> Return superior menu \n");
P();
printf(" ---------------------------------------------------------------\n");
printf(" please choice(1~5): ");
}
void menu3()
{
clrscr();
P();
printf(" --------------------------Select Menu-------------------------\n");
P();
printf(" 1> Chinese 2> Math \n");
P();
printf(" 3> English 4> Computer \n");
P();
printf(" 5> Return the main menu \n");
P();
printf(" ---------------------------------------------------------------\n");
printf(" please choice(1~5): ");
}
void menu4()
{
clrscr();
P();
printf(" --------------------------Select Menu-------------------------\n");
P();
printf(" 1> Chinese ranking 2> math ranking \n");
P();
printf(" 3> English ranking 4> computer ranking \n");
P();
printf(" 5> The total ranking 6> Return superior menu \n");
P();
printf(" ---------------------------------------------------------------\n");
printf(" p lease choice(1~6): "); }
search()
{
int i;
clrscr();
menu2();
scanf("%d",&i);
printf("\n");
switch(i)
{
case 1:search_na();break;
case 2:search_nu();break;
case 3:search_sc();break;
case 4:search_se();break;
case 5:break;
default:printf("input error!\n press any botton to continue");
}
}
search_sc()
{
int i;
char j;
clrscr();
menu2_s();
scanf("%d",&i);
printf("\n");
switch(i)
{case 1:score_ch();break;
case 2:score_ma();break;
case 3:score_en();break;
case 4:score_co();break;
case 5:break;
default:printf("input error! input again?(Y/N): ");scanf("%c",&j);
if((j=='Y')||(j=='y')) search();
if((j=='N')||(j=='n')) break;
}
}
search_na()
{
char a[10];int i,t;char j;
printf("\nplease input the name you want to search: ");
printf("\n");
scanf("%s",a);
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("Name\t|Num\t|Sex\t|Age\t|Chi\t|Math\t|Eng\t|Com\t| \n");
printf("-------------------------------------------------------------------------------\n");
for(i=0,t=0;i<SIZE;i++)
{
if(strcmp(a,s[i].name)==0)
printf("%s\t %d\t %c\t %d\t %d\t %d\t %d\t %d\t\n",s[i].name,s[i].num,s[i].sex,s[i].age,s[i].chinese,s[i].math,s[i].english,s[i].computer),t++;
}
printf("**************************************END**************************************\n");
if(t==0)
{
printf("There is no this student!\ninput again?(Y/N): ");
scanf("%c",&j);
if((j=='Y')||(j=='y')) search_na();
if((j=='N')||(j=='n')) search();
}
}
search_nu()
{int k,i,t;
char j;
printf("please input the number you want to search: ");
scanf("%d",&k);
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("Name\t|Num\t|Sex\t|Age\t|Chi\t|Math\t|Eng\t|Com\t| \n");
printf("-------------------------------------------------------------------------------\n");
for(i=0,t=0;i<SIZE;i++)
{
if(k==s[i].num)
printf("%s\t %d\t %c\t %d\t %d\t %d\t %d\t %d\t\n",s[i].name,s[i].num,s[i].sex,s[i].age,s[i].chinese,s[i].math,s[i].english,s[i].computer),t++;
}
printf("**************************************END**************************************\n");
if(t==0)
{
printf("There is no this student!\ninput again?(Y/N): ");
scanf("%c",&j);
if((j=='Y')||(j=='y')) search_nu();
if((j=='N')||(j=='n')) search();
}
}
search_se()
{int i;
char j,k,t;
printf("please input the sex(f/m): ");
scanf("%c",&j);
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("Name\t|Num\t|Sex\t|Age\t|Chi\t|Math\t|Eng\t|Com\t| \n");
printf("-------------------------------------------------------------------------------\n");
for(i=0,t=0;i<SIZE;i++)
{
if(j==s[i].sex)
printf("%s\t %d\t %c\t %d\t %d\t %d\t %d\t %d\t\n",s[i].name,s[i].num,s[i].sex,s[i].age,s[i].chinese,s[i].math,s[i].english,s[i].computer),t++;
}
printf("**************************************END**************************************\n");
}
score_ch()
{int i,k,j;
char t;
printf("please input a score: ");
scanf("%d",&i);
do
{
if((i<0)&&(i>100))
{printf("score input error!\nplease input again: ");
scanf("%d",&i);
printf("\n");
}
else break;
}while(1);
for(j=0,k=0;j<SIZE;j++)
{if(i==s[i].chinese)
printf("These students have this score:\n");
printf("------Name\tSex\tNumber\tAge\tchinese------\n");
printf(" %s\t%c\t%d\t%d\t%d \n"),k++;
}
if(k==0)
{
printf("There is no student have this score!\ninput again?(Y/N): ");
scanf("%c",&t);
if((t=='Y')||(t=='y')) score_ch();
if((t=='N')||(t=='n')) search();
}
}
score_ma()
{int i,k,j;
char t;
printf("please input a score: ");
scanf("%d",&i);
do
{
if((i<0)&&(i>100))
{printf("score input error!\nplease input again: ");
scanf("%d",&i);
printf("\n");
}
else break;
}while(1);
for(j=0,k=0;j<SIZE;j++)
{if(i==s[i].chinese)
printf("These students have this score:\n");
printf("------Name\tSex\tNumber\tAge\tmath------\n");
printf(" %s\t%c\t%d\t%d\t%d \n"),k++;
}
if(k==0)
{
printf("There is no student have this score!\ninput again?(Y/N): ");
scanf("%c",&t);
if((t=='Y')||(t=='y')) score_ma();
if((t=='N')||(t=='n')) search();
}
}
score_en()
{int i,k,j;
char t;
printf("please input a score: ");
scanf("%d",&i);
do
{
if((i<0)&&(i>100))
{printf("score input error!\nplease input again: ");
scanf("%d",&i);
printf("\n");
}
else break;
}while(1);
for(j=0,k=0;j<SIZE;j++)
{if(i==s[i].chinese)
printf("These students have this score:\n");
printf("------Name\tSex\tNumber\tAge\tenglish------\n");
printf(" %s\t%c\t%d\t%d\t%d \n"),k++;
}
if(k==0)
{
printf("There is no student have this score!\ninput again?(Y/N): ");
scanf("%c",&t);
if((t=='Y')||(t=='y')) score_en();
if((t=='N')||(t=='n')) search();
}
}
score_co()
{int i,k,j;
char t;
printf("please input a score: ");
scanf("%d",&i);
do
{
if((i<0)&&(i>100))
{printf("score input error!\nplease input again: ");
scanf("%d",&i);
printf("\n");
}
else break;
}while(1);
for(j=0,k=0;j<SIZE;j++)
{if(i==s[i].chinese)
printf("These students have this score:\n");
printf("------Name\tSex\tNumber\tAge\tcomputer------\n");
printf(" %s\t%c\t%d\t%d\t%d \n"),k++;
}
if(k==0)
{
printf("There is no student have this score!\ninput again?(Y/N): ");
scanf("%c",&t);
if((t=='Y')||(t=='y')) score_co();
if((t=='N')||(t=='n')) search();
}
}
input()
{
}
modify()
{
}
average()
{int i;
clrscr();
menu3();
scanf("%d",&i);
switch(i)
{case 1:ave_ch();break;
case 2:ave_ma();break;
case 3:ave_en();break;
case 4:ave_co();break;
default:printf("input error!\n");average();break;
}
}
ave_ch()
{char i;
float j,k,t;
j=ch_cl(s);
k=ch_b(s);
t=ch_g(s);
printf("\n----------------Chinese average score----------------\n");
printf(" class\t boys\t girls\t\n");
P();
printf(" %f\t %f\t %f\t\n",j,k,t);
}
int ch_cl(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
sum+=s[i].chinese;
ave=sum/SIZE;
return(ave);
}
int ch_b(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
{if(s[i].sex=='m')
sum+=s[i].chinese;
}
ave=sum/SIZE;
return(ave);;
}
int ch_g(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
{if(s[i].sex=='g')
sum+=s[i].chinese;
}
ave=sum/SIZE;
return(ave);;
}
ave_ma()
{char i;
float j,k,t;
j=ma_cl(s);
k=ma_b(s);
t=ma_g(s);
printf("\n----------------Math average score----------------\n");
printf(" class\t boys\t girls\t\n");
P();
printf(" %f\t %f\t %f\t\n",j,k,t);
}
int ma_cl(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
sum+=s[i].math;
ave=(float)sum/SIZE;
return(ave);
}
int ma_b(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
{if(s[i].sex=='m')
sum+=s[i].math;
}
ave=(float)sum/SIZE;
return(ave);;
}
int ma_g(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
{if(s[i].sex=='g')
sum+=s[i].math;
}
ave=(float)sum/SIZE;
return(ave);;
}
ave_en()
{char i;
float j,k,t;
j=en_cl(s);
k=en_b(s);
t=en_g(s);
printf("\n----------------English average score----------------\n");
printf(" class\t boys\t girls\t\n");
P();
printf(" %f\t %f\t %f\t\n",j,k,t);
}
int en_cl(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
sum+=s[i].english;
ave=(float)sum/SIZE;
return(ave);
}
int en_b(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
{if(s[i].sex=='m')
sum+=s[i].english;
}
ave=(float)sum/SIZE;
return(ave);;
}
int en_g(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
{if(s[i].sex=='g')
sum+=s[i].english;
}
ave=(float)sum/SIZE;
return(ave);;
}
ave_co()
{char i;
float j,k,t;
j=co_cl(s);
k=co_b(s);
t=co_g(s);
printf("\n----------------Computer average score----------------\n");
printf(" class\t boys\t girls\t\n");
P();
printf(" %f\t %f\t %f\t\n",j,k,t);
}
int co_cl(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
sum+=s[i].computer;
ave=(float)sum/SIZE;
return(ave);
}
int co_b(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
{if(s[i].sex=='m')
sum+=s[i].computer;
}
ave=(float)sum/SIZE;
return(ave);;
}
int co_g(struct student s[])
{int ave;
int sum=0,i;
for(i=0;i<SIZE;i++)
{if(s[i].sex=='g')
sum+=s[i].computer;
}
ave=(float)sum/SIZE;
return(ave);;
}
ranking()
{
}
main()
{int i;
clrscr();
textcolor(11);
textbackground(5);
clrscr();
read_in();
do
{
menu();
scanf("%d",&i);
switch(i)
{case 1:search();break;
case 2:input();break;
case 3:modify();break;
case 4:average();break;
case 5:ranking();break;
case 6:exit(0);break;
}
}
while(1);
}