你错的好多都是很基础的语法,比如函数的传参数等等,帮你改的七七八八了,还有错的话你按照我的思路继续改正吧,我不能全帮你改了,毕竟你自己也要知道如何去做,全帮你改了就没意义了,反正大的错应该没了,还有基础方面的东西你还要弄弄,不要上来就做复杂的题目,没好处的.
#include "stdio.h"
#include "stdafx.h"
#include "string.h"
#include "stdlib.h"
#define Cls system("cls") //定义清屏
#define Flush fflush(stdin) //定义输入缓冲区
#define N 10 //定义一个全局变量
struct student
{
int xuehao;
char name[10];
float score1;
float score2;
float score3;
float pingjun;
}stu[N];
int jieshou(struct student stu[], int n) //接受学员信息的子函数
{
char ans;
int i=n;
Cls;
//struct student stu[];
printf("请输入学员信息。\n\n");
while(1/*ans == 'y' && ans == 'Y'*/){
printf("学号:");
scanf("%d", &stu[i].xuehao);
Flush;
printf("\n姓名:");
scanf("%s",stu[i].name);
printf("三门成绩:\n");
scanf("%f%f%f", &stu[i].score1, &stu[i].score2, &stu[i].score3);
//stu[i].pingjun = (stu[i].score1 + stu[i].score2 + stu[i].score3) / 3;
i++;
printf("是否继续输入:(y/n)");
scanf("\n%c", &ans);
if(ans=='n'||ans=='N')
break;
}
//return stu[];
return i;
}
void display(struct student stu[], int m)
{
int i;
Cls;
Flush;
for(i=0;i
{
printf("学号:%d\t姓名:%s\n",stu[i].xuehao,stu[i].name);
printf("三门成绩:\n");
printf("成绩1:%.2f\n成绩2:%.2f\n成绩3:%.2f",stu[i].score1,stu[i].score2,stu[i].score3);
}
getchar();
}
void paixu(struct student stu[], int x) //实现排序的子函数
{
int i, j;
struct student temp;
for (i = 0; i < x; i++)
{
for (j = 0; j < x - i - 1; j++)
{
if (stu[j].pingjun < stu[j + 1].pingjun)
{
temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;
}
}
}
}
void charu(struct student stu[], int x) //实现插入的子函数
{
char ans;
//struct student stu[];
Cls;
printf ("\n是否要插入新学员?(y/n)");
fflush (stdin);
ans = getchar();
if (ans == 'y' || ans == 'Y')
{
printf("学号:");
scanf("%d", &stu[x].xuehao);
fflush(stdin);
printf("\n姓名:");
gets(stu[x].name);
printf("\n三门成绩:");
printf("\n成绩1:");
scanf("%.2lf", &stu[x].score1);
printf("\n成绩2:");
scanf("%.2lf", &stu[x].score2);
printf("\n成绩3:");
scanf("%.2lf", &stu[x].score3);
stu[x].pingjun = (stu[x].score1 + stu[x].score2 + stu[x].score3) / 3;
x++;
}
}
void shanchu(struct student stu[], int x) //实现删除的子函数
{
int i, j, k;
char ans;
ans = 'y';
Cls;
printf("是否要删除学员信息:(y/n)");
fflush(stdin);
scanf("%c", &ans);
if (ans == 'y' && ans == 'Y')
{
printf("请输入需要删除学员的学号:");
scanf("%d", &i);
for (j = 0; j < x; j++)
{
if (stu[j].xuehao == i)
{
break;
}
}
for (k = j; k < (x - 1); k++)
{
stu[k] = stu[k + 1];
}
x--;
paixu(stu, x);
printf ("\n删除后学员的信息如下:");
display(stu, x);
}
/*return x;*/
}
void main() //main函数
{
int y,x=0;
struct student stu[N];
do
{
system("cls");
printf("学员信息表\n");
printf("1.输入学员信息。\n");
printf("2.插入学员信息。\n");
printf("3.对学员信息进行排序:\n");
printf("4.显示学员信息。\n");
printf("5.删除学员信息。\n");
printf("6.退出。\n");
printf("请输入选择项:");
scanf("%d",&y);
switch (y)
{
case 1:
x = jieshou(/*struct student*/stu,x);
break;
case 2:
charu(/*struct student */stu,x);
break;
case 3:
paixu(/*struct student*/ stu,x);
break;
case 4:
display(/*struct student */stu,x);
break;
case 5:shanchu(stu,x);
break;
case 6:
exit(0);
break;
}
}
while(1/*y == 5*/);
}