歌唱比赛评分 哪里错了??求高手指教~~~~
有十个选手参加歌唱比赛,十个裁判对每个选手的演唱进行打分,去掉一个最高分,去掉一个最低分,剩下分数的平均值作为每位选手最后的成绩。要求:
(1)采用结构体定义每个选手的参赛编号,姓名以及十个裁判打出的分数;
(2)从键盘输入每个选手的相关信息:参赛编号,姓名和十个得分;
(3)计算每位选手的最后得分,并按分数由高到低排序;
(4)查询功能:输入参赛选手的编号或姓名,便可输出该选手的得分以及排名;
以上功能采用菜单操作方式。
#include "math.h"
#include "stdio.h"
#include "string.h"
struct Info
{
char number[5];
char name[20];
int mark[10];
int sum;
float finalmark;
};
void Input(struct Info player[],int n);
void Sort(struct Info player[],int n);
int Search(struct Info player[], int n, char x[]);
main()
{
int n=10;
int k,pos;
char x,y,reply;
struct Info player[10];
printf("\n\n");
while(1)
{
system("cls");
printf(" 1. 输入每个选手的相关信息:参赛编号,姓名和十个得分\n");
printf(" 2. 计算每位选手的最后得分,并按分数由高到低排序\n");
printf(" 3. 查询功能:输入参赛选手的编号或姓名,便可输出该选手的得分以及排名\n");
printf(" 4. 退出\n");
printf(" input (1~4)?");
scanf("%d",&k);
switch(k)
{
case 1:printf("Input the information about player:\n");
Input(player,n);
break;
case 2:
printf("The finalmark of player:\n");
Sort(player,n);
break;
case 3:
do
{
printf("Please enter searching number or name:\n");
scanf("%s",x);
pos= Search( player,n,x);
if(pos!=-1)
{
printf("Player's finalmark and sork:\n");
printf(" sork number name finalmark\n");
printf("%d %s %s %4.2f\n",pos+1,player[pos].number,player[pos].name,player[pos].finalmark);
}
else
printf("Not found!\n");
printf("Do you want to continue(Y/N or y/n)?");
scanf("%1s", &reply);
}while (reply == 'Y' || reply == 'y');
break;
case 4:
exit(1);
break;
}
getchar();
getchar();
}
}
void Input(struct Info player[],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("number,name,ten mark\n");
scanf("%s %s",player[i].number,player[i].name);
for(j=0;j<10;j++)
{
scanf("%d",&player[i].mark[j]);
}
}
}
void Sort(struct Info player[],int n)
{
int i,j,k;
int max,min;
struct Info temp1;
for(i=0;i<n;i++)
{
player[i].sum=player[i].mark[0];
max=min=player[i].mark[0];
for(j=1;j<10;j++)
{
player[i].sum=player[i].sum+player[i].mark[j];
if(max<player[i].mark[j])
max=player[i].mark[j];
if(min>player[i].mark[j])
min=player[i].mark[j];
}
player[i].finalmark=(float)(player[i].sum-max-min)/8;
}
for (i=0;i<n-1;i++)
{
k = i;
for(j=i+1;j<n;j++)
{
if (player[j].finalmark>player[k].finalmark)
k = j;
}
if(k!=i)
{
temp1=player[k];
player[k]=player[i];
player[i]=temp1;
}
}
for(i=0;i<n;i++)
{
printf("%s %s %4.2f\n",player[i].number,
player[i].name,player[i].finalmark);
}
}
int Search(struct Info player[], int n, char x[])
{
int i;
for(i=0;i<n;i++)
{
if(strcmp(player[i].number,x)== 0||strcmp(player[i].name,x)==0)
return(i);
}
return (-1);
}