今天写了自主点餐的添加菜品和删除菜品
添加菜品:
//添加菜品信息
void add_food(linklist head)
{
system("cls");
system("color 7D");
linklist prt=head,pre=head->next,p;
linklist q;
while(pre)
{
prt=prt->next;
pre=pre->next;
}
char number[20];
char name[20];
char category[20];
char price[10];
printf("\n请输入需要添加的菜品:\n");
printf("编号\t\t菜名\t\t类别\t\t价格\n");
printf("输入#号结束\n");
while(scanf("%s",number),strcmp(number,"#")!=0)
{
int t=0;
linklist q=head->next;
while(q)
{
if(strcmp(q->number,number)==0)
{
t=1;
break;
}
q=q->next;
}
if(t==0)
{
scanf("%s",name);
scanf("%s",category);
scanf("%s",price);
p=(linklist)malloc(sizeof(lnode));
strcpy(p->number,number);
strcpy(p->name,name);
strcpy(p->category,category);
strcpy(p->price,price);
p->next=prt->next;
prt->next=p;
printf("添加成功\n");
}
if(t==1)
printf("已存在该菜品\n");
}
Ins(head);
}
删除菜品:
//删除菜品信息
void delete_food(linklist head)
{
system("cls");
system("color 7D");
int t=0;
char number[20];
char name[20];
char category[20];
char price[10];
printf("\n请输入需要删除的菜品编号:\n");
scanf("%s",number);
linklist prt=head,pre=head->next,p;
while(pre)
{
if(strcmp(pre->number,number)==0)
{
t=1;
break;
}
pre=pre->next;
prt=prt->next;
}
if(t==1)
{
p=prt->next;
prt->next=p->next;
strcpy(number,p->number);
strcpy(name,p->name);
strcpy(category,p->category);
strcpy(price,p->price);
free(p);
printf("删除成功\n");
}
if(t==0)
printf("不存在该菜品\n");
}
Ins(head);
}