大一c语言餐馆点菜系统代码
时间: 2023-10-12 18:20:56 浏览: 64
以下是一个简单的餐馆点菜系统的 C 语言代码,仅供参考:
```c
#include<stdio.h>
#include<string.h>
int main()
{
char food[10][20]={"spaghetti","pizza","burger","sandwich","sushi","ramen","steak","fried rice","chicken wings","fries"}; // 菜单
int price[10]={50,35,20,15,80,25,100,30,40,10}; // 价格
int order[10]={0}; // 订单
int total_price=0; // 总价
printf("Welcome to our restaurant!\n");
printf("Here is our menu:\n");
for(int i=0;i<10;i++)
{
printf("%d. %s - $%d\n",i+1,food[i],price[i]);
}
printf("You can select up to 3 dishes. Please enter the number of the dish you want to order (1-10), separated by commas:\n");
char input[20];
fgets(input,sizeof(input),stdin);
int len=strlen(input);
if(input[len-1]=='\n')
{
input[len-1]='\0';
}
char *pch=strtok(input,",");
int count=0;
while(pch!=NULL && count<3)
{
int n=atoi(pch);
if(n>=1 && n<=10)
{
order[n-1]++;
total_price+=price[n-1];
count++;
}
pch=strtok(NULL,",");
}
printf("Your order:\n");
for(int i=0;i<10;i++)
{
if(order[i]>0)
{
printf("%s x %d\n",food[i],order[i]);
}
}
printf("Total price: $%d\n",total_price);
return 0;
}
```
该程序实现了以下功能:
1. 显示菜单及价格;
2. 用户可以选择最多三道菜品,并输入其编号;
3. 程序根据用户的输入,计算订单总价;
4. 输出用户的订单及总价。
这只是一个简单的示例,实际的餐馆点菜系统可能要更加复杂和完善。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)