火车管理系统 但是有错误,希望那个能指点一下
#include<stdio.h>#include<string.h>
#include<stdlib.h>
#define N 50;
struct train
{
char checi[10];//车次
char start[20];
char zhondian[20];
int starttime;
int daozhantime;
};
int input(struct train a[]);
void output(struct train a[],int n)
int find(struct train a[],int n,int time);
int correct(struct train a[],int n);
main()
{
struct train train[N];//定义数组
int choice;
int k;//判断是否找到
int number;//记录列车的数量
int time;// 要查询的时间
while(1)
{
menu();
scanf("%d",&choice);
switch(choice)
{
case 1:
number=input(train);
printf("共有%的量火车\n",number);
break;
case 2:
output(train,number);
break;
case 3:
printf("请输入你要查询的时间\n");
scanf("%d",&time);
k=find(train,number,time);
if(i)
printf("找到了\n");
else
printf("没有找到\n");
case 4:
k=correct(train,number);
if(k)
output(train,number);
else
printf("没有此车次的列车\n");
case 5:
exit(0);
break;
}
}
}
void menu()
{
printf("\t1|火车信息的录入\n");
printf("\t2|火车信息的输出\n");
printf("\t3|火车信息的查询\n");
printf("\t4|火车信息的修改\n");
printf("\t5|退出系统\n");
printf("\t请选择\n");
}
//火车信息的录入
int input(struct train a[])
{
int i=0;
int choice=1;
getchar();//清除回车
if(i<N&&choice==1)
{
printf("请输入车次\n");
gets(a[i].checi);
printf("请输入起点站\n");
gets(a[i].start);
printf("请输入终点站\n");
gets(a[i].zhondian);
printf("请输入发车时间\n");
scanf("%d",a[i].starttime);
printf("请输入到站时间\n");
scanf("%d",&a[i].daozhantime);
i++;
printf("是否继续 是(1) 或否(0)");
scanf("%d",&choice);
getchar();//清除回车
}
return i;
}
//火车信息的输入
void output(struct train a[],int n)
{
int i;
printf("\t\t列车时刻表如下\n");
printf("\t车次\t\t发车时间\t\t起点站\t\t终点站\t\t到站时间\n");
for(i=0;i<n;i++)
{
printf("\t%s",a[i].checi);
printf("\t\t%d",a[i].starttime);
printf("\t\t%s",a[i].start);
printf("\t\t%s",a[i].zhondian);
printf("\t\t%d\n",a[i].daozhantime);
}
}
//查询列车
int find(struct train a[],int n,int time)
{
int i=0;
for(i=0;i<n;i++)
{
if(time==a[i].starttime)
break;
}
if(i=n)
return 0;
else
{
printf("\t车次\t\t发车时间\t\t起点站\t\t终点站\t\t到站时间\n");
printf("\t%s",a[i].checi);
printf("\t\t%d",a[i].starttime);
printf("\t\t%s",a[i].start);
printf("\t\t%s",a[i].zhondian);
printf("\t\t%d\n",a[i].daozhantime);
return 1;
}
}
//修改列车信息
int correct(struct train a[],int n)
{
char name[20];
int i;
int j;//判断是否找到
getchar();
printf("请输入你要修改信息的车次名\n");
gets(name);
for(i=0;i<n;i++)
{
if(strcmp(a[i].checi,name)==0)
break;
}
if(i<n)
{
printf("请输入新的发车时间\n");
scanf("%d",a[i].starttime);
printf("请输入终点站\n");
getchar();
scanf("%s",a[i].zhondian);
printf("请输入到站时间\n");
scanf("%d",&a[i].daozhantime);
return 1;
}
else
return 0;
}