今天我们继续完成我们的项目,本次的目标是为每一个分支选项,创建菜单。
分析:1.首先我们要为每一个分支选项创建一个函数
2.其次是调用我们创建的函数
3.最后创建的自定义函数中会用到,while语句,switch语句,在之前的分享中既有这知识点,感兴趣的可以去看看。
运行代码:
#include<stdio.h>//头文件
int record[];//记录,记录价格
void pastries_menu()//面点——菜单
{while (1){int a = 0;printf("欢欢面点菜单\n");printf("1.麻辣排骨面-10元\n");printf("2.阳春面-6元\n");printf("3.炸酱面-8元\n");printf("4.牛肉面-8元\n");printf("5.刀削面-10元\n");printf("6.羊肉泡馍-18元\n");printf("0.点餐结束\n");printf("请选择您想要的面点:");scanf("%d", &a);switch (a){case 1:printf("麻辣排骨面-10元\n");break;case 2:printf("阳春面-6元\n");break; case 3:printf("炸酱面-8元\n");break; case 4:printf("牛肉面-8元\n");break; case 5:printf("刀削面-10元\n");break;case 6:printf("羊肉泡馍-18元\n");break;case 0:printf("感谢您的光临!\n");return 0;default:printf("抱歉没有这项选项!\n");break;}}}void rice_with_toppings_menu()//盖饭菜单
{while (1){int b= 0;printf("欢欢盖饭菜单\n");printf("1.东北大米盖饭-1元\n");printf("2.小炒黄牛肉盖饭-12元\n");printf("3.辣子鸡盖饭-10元\n");printf("4.泡椒肉丝盖饭-10元\n");printf("5.麻辣排骨盖饭-12元\n");printf("6.肉沫茄子盖饭-10元\n");printf("7.酸菜肉丝盖饭-10元\n");printf("0.点餐结束\n");printf("请选择您想要的盖饭:");scanf("%d", &b);switch (b){case 1:printf("东北大米盖饭-1元\n");break;case 2:printf("小炒黄牛肉盖饭-12元\n");break;case 3:printf("辣子鸡盖饭-10元\n");break;case 4:printf("泡椒肉丝盖饭-10元\n");break;case 5:printf("麻辣排骨盖饭-12元\n");break;case 6:printf("肉沫茄子盖饭-10元\n");break;case 7:printf("酸菜肉丝盖饭-10元\n");break;case 0:printf("感谢您的光临!\n");return 0;default:printf("抱歉没有这项选项!\n");break;}}}void special_stir_fried_dish_menu()//小炒菜单
{while (1){int d = 0;printf("欢欢小炒菜单\n");printf("1.西红柿炒鸡蛋-6元\n");printf("2.小炒黄牛肉-12元\n");printf("3.辣子鸡-10元\n");printf("4.泡椒肉丝-10元\n");printf("5.麻辣排骨-12元\n");printf("6.肉沫茄子-10元\n");printf("7.酸菜肉丝-10元\n");printf("0.点餐结束\n");printf("请选择您想要的小炒:");scanf("%d", &d);switch (d){case 1:printf("西红柿炒鸡蛋-6元\n");break;case 2:printf("小炒黄牛肉-12元\n");break;case 3:printf("辣子鸡-10元\n");break;case 4:printf("泡椒肉丝-10元\n");break;case 5:printf("麻辣排骨-12元\n");break;case 6:printf("肉沫茄子-10元\n");break;case 7:printf("酸菜肉丝-10元\n");break;case 0:printf("感谢您的光临!\n");return 0;default:printf("抱歉没有这项选项!\n");break;}}
}void soup_menu()//汤类菜单
{while (1){int e = 0;printf("欢欢汤类菜单\n");printf("1.西红柿鸡蛋汤-6元\n");printf("2.红枣乌鸡汤-12元\n");printf("3.酸菜粉丝汤-6元\n");printf("4.豇豆老鸭汤-12元\n");printf("5.鸭血白菜汤-8元\n");printf("0.点餐结束\n");printf("请选择您想要的汤类:");scanf("%d", &e);switch (e){case 1:printf("西红柿鸡蛋汤-6元\n");break;case 2:printf("红枣乌鸡汤-12元\n");break;case 3:printf("酸菜粉丝汤-6元\n");break;case 4:printf("豇豆老鸭汤-12元\n");break;case 5:printf("鸭血白菜汤-8元\n");break;case 0:printf("感谢您的光临!\n");return 0;default:printf("抱歉没有这项选项!\n");break;}}
}void drink_menu()//饮品菜单
{while (1){int f = 0;printf("欢欢饮品菜单\n");printf("1.橙汁-3元\n");printf("2.可乐-3元\n");printf("3.雪碧-3元\n");printf("4.纯牛奶-3元\n");printf("5.王老吉-3元\n");printf("6.冰糖雪梨-3元\n");printf("0.点餐结束\n");printf("请选择您想要的饮品:");scanf("%d", &f);switch (f){case 1:printf("橙汁-3元\n");break;case 2:printf("可乐-3元\n");break;case 3:printf("雪碧-3元\n");break;case 4:printf("纯牛奶-3元\n");break;case 5:printf("王老吉-3元\n");break;case 6:printf("冰糖雪梨-3元\n");break;case 0:printf("感谢您的光临!\n");return 0;default:printf("抱歉没有这项选项!\n");break;}}
}
int main()//主函数
{while (1)//使用户可以重复选择{int c = 0;printf("欢迎使用欢欢菜单\n");printf("请选择想要商品类型:\n");printf("1.面点\n");printf("2.盖饭\n");printf("3.小炒\n");printf("4.汤类\n");printf("5.饮品\n");printf("0.退出\n");printf("请输入您的选项:");scanf("%d", &c);//接收用户输入的选项switch (c)//为相应的选项提供对应的的答案分支{case 1:printf("您选择了面点!\n");pastries_menu();//函数调用break;case 2:printf("您选择了盖饭!\n");rice_with_toppings_menu();//函数调用break;case 3:printf("您选择了小炒!\n");special_stir_fried_dish_menu();//函数调用break;case 4:printf("您选择了汤类!\n");soup_menu();//函数调用break;case 5:printf("您选择了饮品!\n");drink_menu();//函数调用break;case 0:printf("感谢您的光临!\n");return 0;//直接结束整个程序default:printf("抱歉没有这项选项!\n");break;}}return 0;
}
运行结果:
完