2 u011182623 u011182623 于 2013.06.26 22:37 提问

请问这个程序怎么修改,总是提示一个错误

#include
#include
#include
#include
#define N 3
#define M 10
int add = N-1;
int sum[N]={0},Max[N],Min[N];
float aver[N]={0};
struct player
{
int num;
char name[8];
int score[M];
}PL;
void Inistplayer(PL player[],int n)
{
int i;
for(i=0;i scanf("%d%s",&player[i].num,player[i].name);
}
void Inputscore(int score[],int n)
{
int i;
for(i=0;i score[i]=1+(int)10*rand()/(RAND_MAX+1);
}
void sort(PL player[],float b[],int n)
{
int i,k,j,t;
float temp;
char str[8];
for(i=0;i {
k=i;
for(j=i+1;j if(b[k]>b[j])
k=j;
if(k!=i)
{
temp=b[i];
b[i]=b[k];
b[k]=temp;
strcpy(str,player[i].name);
strcpy(player[i].name,player[k].name);
strcpy(player[k].name,str);
t=player[i].num;
player[i].num=player[k].num;
player[k].num=t;
}
}
}
void main()
{
int flag=1,n,i,m,j;
FILE fp;
fp = fopen("data.txt","w+");
PL player[20];
printf("
*********1.输入选手数据***********\n");
printf("**********2.评委打分***************\n");
printf("**********3.成绩排序***************\n");
printf("**********4.数据查询***************\n");
printf("**********5.追加学生数据***********\n");
printf("**********6.写入数据文件***********\n");
printf("**********7.退出系统***************\n");
while(flag)
{
printf("你想进行的操作:");
scanf("%d",&n);
switch(n)
{
case 1:Inistplayer(player,N);break;
case 2:srand((unsigned)time(NULL));
for(i=0;i {
printf("%d位选手的成绩:",i+1);
Inputscore(player[i].score,M);
for(j=0;j printf("%d ",player[i].score[j]);
printf("\n");
}
break;
case 3:for(i=0;i {
Max[i]=player[i].score[0];
Min[i]=player[i].score[0];
for(j=0;j {
sum[i]+=player[i].score[j];
if(Max[i] Max[i]=player[i].score[j];
if(Min[i]>player[i].score[j])
Min[i]=player[i].score[j];
}
aver[i]=(float)(sum[i]-Max[i]-Min[i])/(M-2);
}
sort(player,aver,N);
for(i=0;i<N;i++)
printf("%s %5.2f\n",player[i].name,aver[i]);*/
break;
case 4:printf("你想查询选手的数据:");
scanf("%d",&m);
for(i=0;i<N;i++)
if(player[i].num==m)
{
printf("%d号选手%s总分:%d,最高分%d,最低分%d,平均分%5.2f",player[i].num,player[i].name,sum[i],Max[i],Min[i],aver[i]);
printf("\n");
}
break;
case 5:printf("请输入要追加的选手数据:\n");
add += 1;
scanf("%d%s",&player[add].num,player[add].name);

break;
case 6:printf("将数据写入文件中:\n");
for (i = 0 ; i < add+1 ; i++)
{
fprintf(fp,"%d ",player[i].num);
fprintf(fp,"%s ",player[i].name);
fprintf(fp,"%d\n",player[i].score);
}
break;
case 7:exit(0);
break;
default:flag=0;
}
}
}

2个回答

lijianhuilijie
lijianhuilijie   2013.07.17 16:46
已采纳

for(j=i+1;j if(b[k]>b[j])
k=j;
if(k!=i)茫然了

a1193561652
a1193561652   Rxr 2015.05.19 16:07

格式好乱,特别是sort()函数里的第一个for循环,好像后面掉了一部分,另外main()函数的返回值应为int型。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!