帮看看这个程序的错误 急~
忙了一天了课程设计终于快做完但是还存在点问题怎么也看不出来了
1:设想的输入a进入 total函数输入b进入math函数 但是为什么都是指向total函数的?
2:求平均数结果不对,没找到问题
3:如何在执行一个函数以后回到输入字母选择函数那步?
谢了
#include "stdio.h "
#include "bios.h "
#include "stdlib.h "
int total();
int math();
int chinese();
int english();
int chemistry();
int physics();
int biology();
static struct s
{
char name[10];
int math;
int chinese;
int english;
int chemistry;
int physics;
int biology;
}list[40];
main()
{
int point[40],i,j,p,n;
char h;
int key;
clrscr();
for(n=0;n <40;n++)
{
printf( "input the ESC to quit,or enter any other key\n ");
fflush(stdin);
key=bioskey(0)&0xff;
if((key&27)==27)
break;
else
{
printf( "please input the No.%d student information\n ",n+1);
scanf( "%s%d%d%d%d%d%d ",list[n].name,&list[n].math,&list[n].chinese,&list [n].english, &list[n].chemistry, &list[n].physics,&list[n].biology);
}
}
printf( "What can I do for you?\nA Total list\nB Math\nC Chinese\nD English\n E Chemistry\nF Physics \nG Biology ");
h=getchar();
if(h= 'a ') total(n);
else
if(h= 'b ') math(n);
else
if(h= 'c ') chinese(n);
else
if(h= 'd ') english(n);
else
if(h= 'e ') chemistry(n);
else
if(h= 'f ') physics(n);
else
if(h= 'g ') biology(n);
else printf( "error ");
}
int total(int a)
{
int i,j,p,point[40];
struct s t;
for(i=0;i <40;i++)
point[i]=list[i].chinese+list[i].english+list[i].chemistry+list[i].physics+list[i].biology;
for(j=0;j <40;j++)
{
for(i=0;i <40;i++)
{
if(point[i] <point[j])
{
t=list[i];
list[i]=list[j];
list[j]=t;
p = point[i];
point[i] = point[j];
point[j] = p;
}
}
}
clrscr();
printf( "name math chinese english chemistry physics biology totla\n ");
for(i=0;i <a;i++)
printf( "%-10s%-10d%-10d%-10d%-5d%10d%10d%10d\n ",list[i].name,list[i].math,list[i].chinese,list[i].english, list[i].chemistry, list[i].physics,list[i].biology,point[i]);
return(0);
}
int math(int a)
{
int i,j;
struct s t;
float average;
for(j=0;j <40;j++)
{
for(i=0;i <40;i++)
{
if(list[i].math <list[j].math)
{
t=list[i];
list[i]=list[j];
list[j]=t;
}
}
}
clrscr();
printf( "name math\n ");
for(i=0;i <a;i++)
printf( "%-10s%-10d\n ",list[i].name,list[i].math);
for(i=0;i <a;i++)
average=(average+list[i].math);
average=average/a;
printf( "average=%f ",average);
return(0);
}
int chinese(int a)
{
int i,j;
struct s t;
float average;
for(j=0;j <40;j++)
{
for(i=0;i <40;i++)
{
if(list[i].chinese <list[j].chinese)
{
t=list[i];
list[i]=list[j];
list[j]=t;
}
}
}
clrscr();
printf( "name chinese\n ");
for(i=0;i <a;i++)
printf( "%-10s%-10d\n ",list[i].name,list[i].chinese);
for(i=0;i <a;i++)
average=(average+list[i].chinese);
average=average/a;
printf( "average=%f ",average);
return(0);
}
int english(int a)
{
int i,j;
struct s t;
float average;
for(j=0;j <40;j++)
{
for(i=0;i <40;i++)
{
if(list[i].english <list[j].english)
{
t=list[i];
list[i]=list[j];
list[j]=t;
}
}
}
clrscr();
printf( "name english\n ");
for(i=0;i <a;i++)
printf( "%-10s%-10d\n ",list[i].name,list[i].english);
for(i=0;i <a;i++)
average=(average+list[i].english);
average=average/a;
printf( "average=%f ",average);
return(0);
}
int chemistry(int a)
{
int i,j;
struct s t;
float average;
for(j=0;j <40;j++)
{
for(i=0;i <40;i++)
{
if(list[i].chemistry <list[j].chemistry)
{
t=list[i];
list[i]=list[j];
list[j]=t;
}
}
}
clrscr();
printf( "name chemistry\n ");
for(i=0;i <a;i++)
printf( "%-10s%-10d\n ",list[i].name,list[i].chemistry);
for(i=0;i <a;i++)
average=(average+list[i].chemistry);
average=average/a;
printf( "average=%f ",average);
return(0);
}
int physics(int a)
{
int i,j;
struct s t;
float average;
for(j=0;j <40;j++)
{
for(i=0;i <40;i++)
{
if(list[i].physics <list[j].physics)
{
t=list[i];
list[i]=list[j];
list[j]=t;
}
}
}
clrscr();
printf( "name physics\n ");
for(i=0;i <a;i++)
printf( "%-10s%-10d\n ",list[i].name,list[i].physics);
for(i=0;i <a;i++)
average=(average+list[i].physics);
average=average/a;
printf( "average=%f ",average);
return(0);
}
int biology(int a)
{
int i,j;
struct s t;
float average;
for(j=0;j <40;j++)
{
for(i=0;i <40;i++)
{
if(list[i].biology <list[j].biology)
{
t=list[i];
list[i]=list[j];
list[j]=t;
}
}
}
clrscr();
printf( "name biology\n ");
for(i=0;i <a;i++)
printf( "%-10s%-10d\n ",list[i].name,list[i].biology);
for(i=0;i <a;i++)
average=(average+list[i].biology);
average=average/a;
printf( "average=%f ",average);
return(0);
}
[解决办法]
先沙发