#include
#include
#include
#include
int n=0;//歌手的结构体
typedef struct singer
{
int num;//编号
char name[20];//姓名
int score[10];//十个评委的评分
int sum;//总分
float average;//平均分
struct singer *next; //结构体的内部指针
}Singer;
void Menu();
Singer *create();
void grade(Singer *head);
void print(Singer *head);
int main()
{
Singer *head=NULL;
int choice;
while (1)
{
system("cls");
Menu();
scanf("%d", &choice);
switch (choice)
{
case 1:
//输入选手数据
head=create();
break;
//评委打分
case 2:
grade(head);
break;
//查看所有数据
case 4:
print(head);
break;
}
}
return 0;
}
void Menu()
{
printf("\t\t\t ————————\n");
printf("\t\t\t | 歌手比赛系统 | \n");
printf("\t\t\t ————————\n");
printf("\t\t\t1.输入选手数据\n");
printf("\t\t\t2.评委打分\n");
printf("\t\t\t3.成绩排序\n");
printf("\t\t\t4.数据查询\n");
printf("\t\t\t5.追加选手数据\n");
printf("\t\t\t6.写入数据文件\n");
printf("\t\t\t7.退出系统\n");
printf("\t\t\t请选择:");
}
Singer create()
{
system("cls");
Singer *q,*p,*head;
head=NULL;
q=p=(Singer)malloc(sizeof(Singer));
while(1)
{
n++;
if(n==1)
head=p;
else q->next=p;
q=p;
p=(Singer*)malloc(sizeof(Singer));
printf("请输入选手的编号:(输0结束)");
scanf("%d",&p->num);
if(p->num==0)
break;
printf("请输入选手的姓名:");
scanf("%s",&p->name);
}
q->next =NULL;
printf("输入结束!");
return head;
}
//显示全部数据
void print ( Singer *head)
{
Singer *p=head;
if(p!=NULL)
{
printf("编号 姓名 总分 平均分");
while(p!=NULL)
{
printf("%d %s %d %d",p->num,p->name,p->sum,p->average);
p=p->next;
}
}
else
printf("没有选手信息");
}
void grade(Singer *head)
{
system("cls");
Singer *p;
p=head;
if(p!=NULL)
{
while(p!=NULL)
{
int i,number;
printf("请输入要打分的选手的编号:");
scanf("%d",&number);
if(p->num==number)
{
for(i=0;i { printf("请输入第%d位评委的评分",i+1);
scanf("%d",&p->score[i]);
}
}
else
printf("没有该选手!");
}
}
}
大佬们,帮帮忙,改了半天还是一样的
链表没有错,感觉grade函数有错误,改成下面这样试试:
void grade(Singer *head)
{
system("cls");
Singer *p;
p=head;
if(p!=NULL)
{
bool flag = false;
int i,number;
printf("请输入要打分的选手的编号:");
scanf("%d",&number);
while(p!=NULL)
{
if(p->num==number)
{
flag = true;
for(i=0;i<10;i++)
{
printf("请输入第%d位评委的评分",i+1);
scanf("%d",&p->score[i]);
}
}
else
p=p->next;
}
if (!flag)
{
printf("没有选手信息");
}
}
}