军工路快速路 建成时间:C语言问题!

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/28 20:42:58
我在VC6上写的一个裁判评分处理的程序,怎么在RUN到“计算平均分”那就出错了?
高手给看看啊,谢谢!!
在线=!!
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define LEN sizeof(struct singer)
#define JUDGENUM 3

struct singer
{

int num; //选手考号
char name[20];//选手姓名
float score[JUDGENUM];//9个评委的给分
float average;//选手的最终成绩
struct singer *next;//链
}
//非模块化的实现
main()
{
int i,j,n,playernum=0;
float s=0.0; //和
struct singer *head,*tem,*p1,*p2;
printf("Please input the tatol number of player:\n");
scanf("%d",&playernum);
//printf("Please input the information of player just as the order:\nnumberofplayer name score\n");
n=1;

//建立链表并读入数据
while(playernum>=n)
{
if(1==n) //头指针设置
{

p1=(struct singer*)malloc(LEN);
printf("Which player\'s num\n");
scanf("%d",&p1->num);

printf("The name of num%d:\n",p1->num);
scanf("%s",p1->name);
for(i=1;i<=JUDGENUM;i++)
{
printf("The mark of judge%d\n",i);
scanf("%f",&p1->score[i-1]);
}
tem=head=p1;
}
else
{
p2=(struct singer*)malloc(LEN);
printf("Which palyer\'s num\n");
scanf("%d",&p2->num);
printf("The name of num%d:\n",p2->num);
scanf("%s",p2->name);
for(i=1;i<=JUDGENUM;i++)
{
printf("The mark of judge%d\n",i);
scanf("%f",&p2->score[i-1]);
}
p1->next=p2;
p1=p2;
}
n++;
}
printf("还好!!");
//处理数据
for(i=1;i<=playernum;i++)
{
//去掉最高和最低分
for(n=1;n<=JUDGENUM;n++)
{
if(head->score[n]>head->score[0])
head->score[0]=head->score[n];
}
for(n=1;n<=JUDGENUM;n++)
{
if(head->score[n]<head->score[JUDGENUM])
head->score[JUDGENUM]=head->score[n];
}
//计算平均分
j=1;
while(j<=playernum)
{
for(n=1;n<JUDGENUM;n++)
s+=tem->score[n];
tem->average=s/(JUDGENUM-2);
if(1==j) head=tem;
tem=tem->next;
j++;
}

}
printf("haohao ");
printf("%f",head->average);
printf("haohaooo ");
//利用冒泡排序对average进行排列
for(i=0;i<playernum-1;i++)
{

for(j=i;j<playernum-1;j++)
{
if(0==j) p1=head->next;
if(p1->average >head->average )
{
p2 = head;
head = p1;
head->next = p2;
p2->next = p1->next;
}
p1=p1->next;

}
head = head->next ;
}
//输出结果
printf("**************************final result of singers is bellow**************************\n");
printf("Sorted_number player Average_Score\n");
j=1;
while(j<=playernum)
{
printf("%30d%30s%f\n",j,head->name,head->average);
head=head->next;
}
}
写的很匆忙,是很乱,呵呵

自己跟一下程序吧,tem->score[n]的值非法

好乱啊

好乱啊?