我把定义的变量都提到最前就没有错误了 然后具体的内容你就要自己再仔细看看咯·····
#include <stdio.h>
#include <string.h>
void menu(void)
{
printf("1. information input\n");
printf("2. information revise\n");
printf("3. information delete\n");
printf("4. information search\n");
printf("Please enter your choice:");
}
main()
{
int a, i, j,e;
char c,cc,d, u,mm[10],p;
struct STUDENT
{
int num;
char name[10];
int term;
int scoreMath;
int scoreEnglish;
int scoreChinese;
float average;
int sum;
};struct STUDENT abc;
struct STUDENT stu[1000];
printf("please enter student number:");
scanf("%d",&a);
menu();
getchar();
c=getchar();
switch(c)
{
case '1':
printf("please enter student num:");
getchar();
for(i=0;i<a;i++)
{
scanf("%d", &stu[i].num);getchar();
}
printf("please enter student name:");
for(i=0;i<a;i++)
{
scanf("%s", stu[i].name);
}
printf("please enter term:");
getchar();
for(i=0;i<a;i++)
{
scanf("%d", &stu[i].term);
}
printf("please enter student scoreMath:");
getchar();
for(i=0;i<a;i++)
{
scanf("%d", &stu[i].scoreMath);
}
printf("please enter student scoreEnglish:");
getchar();
for(i=0;i<a;i++)
{
scanf("%d", &stu[i].scoreEnglish);
}
printf("please enter student scoreChinese:");
getchar();
for(i=0;i<a;i++)
{
scanf("%d", &stu[i].scoreChinese);
}
for(i=0;i<a;i++)
{
stu[i].sum=stu[i].scoreMath+stu[i].scoreEnglish+stu[i].scoreChinese;
stu[i].average=stu[i].sum/4;
}
for(i=0;i<a-1;i++)
{
for(j=i+1;j<a;j++)
{
if(stu[j].sum > stu[i].sum)
{
abc=stu[i];
stu[i]=stu[j];
stu[j]=abc;
}
}
}
for(i=0;i<a;i++)
{
printf("NO. : %d Name : %s Term : %d ScoreMath : %d ScoreEnglish : %d ScoreChinese : %d Sum : %d Average : %f Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum, stu[i].average, i+1 );
printf("\n\n");
}
menu();
break;
case '2':
printf("please enter student num:");
scanf("%d", &c);
printf("please choice the error:");
printf("1. num\n");
printf("2. name\n");
printf("3. term\n");
printf("4. scoreMath\n");
printf("5. scoreEnglish:");
printf("6. scoreChinese:");
printf("Please enter your choice:");
p=getchar();
switch(p)
{
case '1':
printf("please enter the new one:");
scanf("%d", &stu[c].num);
break;
case '2':
printf("please enter the new one:");
scanf("%d", stu[c].name);
break;
case '3':
printf("please enter the new one:");
scanf("%d", &stu[c].term);
break;
case '4':
printf("please enter the new one:");
scanf("%d", &stu[c].scoreMath);
break;
case '5':
printf("please enter the new one:");
scanf("%d", &stu[c].scoreEnglish);
break;
case '6':
printf("please enter the new one:");
scanf("%d", &stu[c].scoreChinese);
break;
default:
printf("Input error!");
}
for(i=0;i<a;i++)
{
stu[i].sum=stu[i].scoreMath+stu[i].scoreEnglish+stu[i].scoreChinese;
stu[i].average=stu[i].sum/4;
}
for(i=0;i<a-1;i++)
{
for(j=i+1;j<a;j++)
{
if(stu[j].sum > stu[i].sum)
{
abc=stu[i];
stu[i]=stu[j];
stu[j]=abc;
}
}
}
for(i=0;i<a;i++)
{
printf("NO. : %d Name : %s Term : %d ScoreMath : %d ScoreEnglish : %d ScoreChinese : %d Sum : %d Average : %f Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum, stu[i].average, i+1 );
printf("\n\n");
}
menu();
break;
case '3':
printf("Please enter the delete number:");
scanf("%d", &d);
for(i=0;i<a;i++)
{
if(d==stu[i].num)
{
for(i=0;i<a-1;i++)
{
stu[i]=stu[i+1];
}
for(i=0;i<a-1;i++)
{
printf("NO. : %d Name : %s Term : %d ScoreMath : %d ScoreEnglish : %d ScoreChinese : %d Sum : %d Average : %f Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum, stu[i].average, i+1 );
printf("\n\n");
}
}
}
menu();
break;
case '4':
printf("please choice the information your want to search:");
printf("1. num\n");
printf("2. name\n");
printf("Please enter your choice:");
u=getchar();
switch(u)
{
case '1':
printf("Please enter the number:");
scanf("%d", &e);
for(i=0;i<a;i++)
{
if(e==stu[i].num)
{
printf("NO. : %d Name : %s Term : %d ScoreMath : %d ScoreEnglish : %d ScoreChinese : %d Sum : %d Average : %f Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum, stu[i].average, i+1 );
break;
}
}
case '2':
printf("Please enter the name:");
scanf("%s", mm);
for(i=0;i<a;i++)
{
if(strcmp(mm, stu[i].name) == 0 )
{
printf("NO. : %d Name : %s Term : %d ScoreMath : %d ScoreEnglish : %d ScoreChinese : %d Sum : %d Average : %f Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum, stu[i].average, i+1 );
printf("\n\n");
break;
}
}
default:
printf("Input error!");
}
menu();
break;
default:
printf("Input error!");
menu();
}
}
#include <stdio.h>
#include <string.h>
void menu(void)
{
printf("1. information input\n");
printf("2. information revise\n");
printf("3. information delete\n");
printf("4. information search\n");
printf("Please enter your choice:");
}
main()
{
int a, i, j,e;
char c,cc,d, u,mm[10],p;
struct STUDENT
{
int num;
char name[10];
int term;
int scoreMath;
int scoreEnglish;
int scoreChinese;
float average;
int sum;
};struct STUDENT abc;
struct STUDENT stu[1000];
printf("please enter student number:");
scanf("%d",&a);
menu();
getchar();
c=getchar();
switch(c)
{
case '1':
printf("please enter student num:");
getchar();
for(i=0;i<a;i++)
{
scanf("%d", &stu[i].num);getchar();
}
printf("please enter student name:");
for(i=0;i<a;i++)
{
scanf("%s", stu[i].name);
}
printf("please enter term:");
getchar();
for(i=0;i<a;i++)
{
scanf("%d", &stu[i].term);
}
printf("please enter student scoreMath:");
getchar();
for(i=0;i<a;i++)
{
scanf("%d", &stu[i].scoreMath);
}
printf("please enter student scoreEnglish:");
getchar();
for(i=0;i<a;i++)
{
scanf("%d", &stu[i].scoreEnglish);
}
printf("please enter student scoreChinese:");
getchar();
for(i=0;i<a;i++)
{
scanf("%d", &stu[i].scoreChinese);
}
for(i=0;i<a;i++)
{
stu[i].sum=stu[i].scoreMath+stu[i].scoreEnglish+stu[i].scoreChinese;
stu[i].average=stu[i].sum/4;
}
for(i=0;i<a-1;i++)
{
for(j=i+1;j<a;j++)
{
if(stu[j].sum > stu[i].sum)
{
abc=stu[i];
stu[i]=stu[j];
stu[j]=abc;
}
}
}
for(i=0;i<a;i++)
{
printf("NO. : %d Name : %s Term : %d ScoreMath : %d ScoreEnglish : %d ScoreChinese : %d Sum : %d Average : %f Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum, stu[i].average, i+1 );
printf("\n\n");
}
menu();
break;
case '2':
printf("please enter student num:");
scanf("%d", &c);
printf("please choice the error:");
printf("1. num\n");
printf("2. name\n");
printf("3. term\n");
printf("4. scoreMath\n");
printf("5. scoreEnglish:");
printf("6. scoreChinese:");
printf("Please enter your choice:");
p=getchar();
switch(p)
{
case '1':
printf("please enter the new one:");
scanf("%d", &stu[c].num);
break;
case '2':
printf("please enter the new one:");
scanf("%d", stu[c].name);
break;
case '3':
printf("please enter the new one:");
scanf("%d", &stu[c].term);
break;
case '4':
printf("please enter the new one:");
scanf("%d", &stu[c].scoreMath);
break;
case '5':
printf("please enter the new one:");
scanf("%d", &stu[c].scoreEnglish);
break;
case '6':
printf("please enter the new one:");
scanf("%d", &stu[c].scoreChinese);
break;
default:
printf("Input error!");
}
for(i=0;i<a;i++)
{
stu[i].sum=stu[i].scoreMath+stu[i].scoreEnglish+stu[i].scoreChinese;
stu[i].average=stu[i].sum/4;
}
for(i=0;i<a-1;i++)
{
for(j=i+1;j<a;j++)
{
if(stu[j].sum > stu[i].sum)
{
abc=stu[i];
stu[i]=stu[j];
stu[j]=abc;
}
}
}
for(i=0;i<a;i++)
{
printf("NO. : %d Name : %s Term : %d ScoreMath : %d ScoreEnglish : %d ScoreChinese : %d Sum : %d Average : %f Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum, stu[i].average, i+1 );
printf("\n\n");
}
menu();
break;
case '3':
printf("Please enter the delete number:");
scanf("%d", &d);
for(i=0;i<a;i++)
{
if(d==stu[i].num)
{
for(i=0;i<a-1;i++)
{
stu[i]=stu[i+1];
}
for(i=0;i<a-1;i++)
{
printf("NO. : %d Name : %s Term : %d ScoreMath : %d ScoreEnglish : %d ScoreChinese : %d Sum : %d Average : %f Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum, stu[i].average, i+1 );
printf("\n\n");
}
}
}
menu();
break;
case '4':
printf("please choice the information your want to search:");
printf("1. num\n");
printf("2. name\n");
printf("Please enter your choice:");
u=getchar();
switch(u)
{
case '1':
printf("Please enter the number:");
scanf("%d", &e);
for(i=0;i<a;i++)
{
if(e==stu[i].num)
{
printf("NO. : %d Name : %s Term : %d ScoreMath : %d ScoreEnglish : %d ScoreChinese : %d Sum : %d Average : %f Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum, stu[i].average, i+1 );
break;
}
}
case '2':
printf("Please enter the name:");
scanf("%s", mm);
for(i=0;i<a;i++)
{
if(strcmp(mm, stu[i].name) == 0 )
{
printf("NO. : %d Name : %s Term : %d ScoreMath : %d ScoreEnglish : %d ScoreChinese : %d Sum : %d Average : %f Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum, stu[i].average, i+1 );
printf("\n\n");
break;
}
}
default:
printf("Input error!");
}
menu();
break;
default:
printf("Input error!");
menu();
}
}