请大佬看下为什么录入函数运行出来是这种情况?麻烦说一下怎么改
#include "pch.h"
#include<string>
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
typedef struct flight
{
char destination[20];//终点站
char flight_number[20];//航班编号
char airplane_nuber[20];//飞机编号
char flightweek[20];//飞行日
int carrying_capacity;//乘员定额
int more_ticket_quantity;//剩余票量
char flightdate[20];//飞行日期
struct flight *next;
}flight, *Flight;
typedef struct custumer
{
int seat_number;//座位号
char name[20];//乘客姓名
int number;//所需票量
int rank;//机舱等级
struct custumer *next;
}custumer,*Custumer;
typedef struct wcustumer
{
char wname[20];//候补客户的姓名
int wnumber;//所需票量
struct wcustumer *next;
}wcustumer,*Wcustumer;
void write(Flight& m,Custumer& cu,Wcustumer& w)//录入航班信息
{//生成三个带有头结点单链表
Flight p;//生成新节点
Wcustumer wc;//生成新节点
Custumer c;//生成新节点
m = (Flight)malloc(sizeof(Flight));
cu = (Custumer)malloc(sizeof(Custumer));
w = (Wcustumer)malloc(sizeof(Wcustumer));
cu->next = NULL;
w->next = NULL;
m->next = NULL;
for (int i = 0; i < 3; i++)
{
printf("请输入您要录入的数据 ");
p = (Flight)malloc(sizeof(Flight));
c = (Custumer)malloc(sizeof(Custumer));
wc = (Wcustumer)malloc(sizeof(Wcustumer));
printf("乘客姓名 所需票量 座位号 机舱等级 ");
scanf_s("%c%d%d%d",&c->name, &c->number, &c->seat_number, &c->rank);
printf("候补客户姓名 所需票量 ");
scanf_s("%c%d",&wc->wname,20, &wc->wnumber);
fflush(stdin);
printf("终点站 航班编号 飞机编号 飞行日 乘员定额 剩余票量 飞行日期 ");
scanf_s("%c%c%c%c%d%d%c", &p->destination,20, &p->flightdate,20, &p->airplane_nuber,20, &p->flightweek,20, &p->carrying_capacity, &p->more_ticket_quantity, &p->flightdate,20);
p->next = m->next;
m->next = p;
c->next = cu->next;
cu->next = c;
w->next = wc->next;
wc->next = w;
}
printf("录入系统完毕 ");
}
void find(Flight &f)//查询航班信息
{
char aim[20];
f = (Flight)malloc(sizeof(Flight));
printf("请输入航班号 ");
scanf_s("%c",&aim,20);
if(f->destination!=aim)
f = f->next;
else
cout << "航班号:" << f->flight_number << " " << "飞机号:" << f->airplane_nuber << " " << "飞行日期:" << f->flightweek << " " << "剩余票量" << f->more_ticket_quantity << endl;
}
void book(Flight &z, Custumer &a)//实现订票业务
{
z = (Flight)malloc(sizeof(Flight));
a = (Custumer)malloc(sizeof(Custumer));
string m;
int n;
cout << "请输入查询的航班号:";
cin >> m;
cout << "请输入您要订票数额:";
cin >> n;
while (z->flight_number != m && z->next != NULL)
{
z = z->next;
}
if (z->next == NULL)
{
int c;
string name;
int id;
int cabin;
cout << "剩余票量不足" << endl;
cout << "是否需要其他帮助按'1'确定,按'0'退出系统" << endl;
cin >> c;
switch (c)
{
case'1':cout << "名字" << " " << "身份证号码" << " " << "选择机舱等级" << endl;
cin >> name >> id >> cabin;
break;
case'0':cout << "退出系统" << endl;
break;
}
}
if (n > z->more_ticket_quantity)
{
int c;
string name;
int id;
int cabin;
cout << "剩余票量不足" << endl;
cout << "是否需要其他帮助按'1'确定,按'0'退出系统" << endl;
cin >> c;
switch (c)
{
case'1':cout << "名字" << " " << "身份证号码" << " " << "选择机舱等级" << endl;
cin >> name >> id >> cabin;
break;
case'0':cout << "退出系统" << endl;
break;
}
}
else
{
while (a->next != NULL)
{
a = a->next;
}
cout << "订票成功座位号为" << a->seat_number + 1 << endl;
}
}
void refound(Flight &d,Custumer &e,Wcustumer &g)//实现退票业务
{
d = (Flight)malloc(sizeof(Flight));
e = (Custumer)malloc(sizeof(Custumer));
g = (Wcustumer)malloc(sizeof(Wcustumer));
string data;
string number;
string name;
cout << "输入您所定航班的日期:";
cin >> data;
while (d->flightdate!=data && d->next != NULL)
{
d = d->next;
}
if (d->next == NULL)
cout << "无此航班日期" << endl;
else
{
cout << "输入您的航班编号:";
cin >> number;
while (d->flight_number && d->next != NULL)
{
d = d->next;
}
if (d->next == NULL)
cout << "无效航班编号" << endl;
else
cout << "姓名:" << name << endl;
while (e->name != name && e->next != NULL)
{
e = e->next;
}
if (e->next == NULL)
cout << "无效姓名" << endl;
else
cout << "成功退票%d张" << e->number << endl;
}
if (g->next == NULL)
cout << "无候补人员" << endl;
else
{
cout << "候补人员是否订票按'1'确定按'0'退出系统" << endl;
int n;
cin >> n;
switch (n)
{
case'1':
{
if (g->wnumber <= e->number)
cout << "订票成功" << endl;
else
cout << "票额不足" << endl;
break;
}
case'0':cout << "退出系统" << endl;
break;
}
}
}
void main()
{
Flight x;
Wcustumer w;
Custumer c;
int n;
while (1)
{
cout << "===========================================" << endl;
cout << " 欢迎使用航空订票系统 " << endl;
cout << "===========================================" << endl;
cout << " 本系统有如下操作 " << endl;
cout << " 1 录入航班信息 " << endl;
cout << " 2 查询航线 " << endl;
cout << " 3 实现订票业务 " << endl;
cout << " 4 实现退票业务 " << endl;
cout << "请选择您的操作:";
cin >> n;
switch (n)
{
case 1: write(x,c,w);
break;
case 2:find(x);
break;
case 3:book(x, c);
break;
case 4:refound(x, c, w);
break;
default:
cout << "退出系统" << endl;
}
}
}
程序明显有问题啊
%c只能输入1个字符
%s才是输入字串(字符数组的)