c语言订餐系统的界面程序
时间: 2023-08-24 14:07:17 浏览: 49
以下是一个简单的C语言订餐系统的界面程序:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_MENU_ITEMS 10
struct menu_item {
char name[50];
double price;
};
struct order {
char item[50];
int quantity;
double total_price;
};
struct menu_item menu[MAX_MENU_ITEMS];
int menu_size = 0;
void add_menu_item(char* name, double price) {
if (menu_size >= MAX_MENU_ITEMS) {
printf("Menu is full. Cannot add item.\n");
return;
}
struct menu_item item;
strcpy(item.name, name);
item.price = price;
menu[menu_size++] = item;
}
void print_menu() {
printf("Menu:\n");
for (int i = 0; i < menu_size; ++i) {
printf("%d. %s - $%.2f\n", i + 1, menu[i].name, menu[i].price);
}
}
int main() {
add_menu_item("Burger", 5.99);
add_menu_item("Pizza", 9.99);
add_menu_item("Pasta", 7.99);
printf("Welcome to the restaurant!\n");
while (1) {
printf("What would you like to do?\n");
printf("1. View menu\n");
printf("2. Place order\n");
printf("3. Exit\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
print_menu();
break;
case 2: {
struct order new_order;
printf("Enter item name: ");
scanf("%s", new_order.item);
printf("Enter quantity: ");
scanf("%d", &new_order.quantity);
for (int i = 0; i < menu_size; ++i) {
if (strcmp(menu[i].name, new_order.item) == 0) {
new_order.total_price = menu[i].price * new_order.quantity;
printf("Total price: $%.2f\n", new_order.total_price);
break;
}
if (i == menu_size - 1) {
printf("Item not found in menu.\n");
}
}
break;
}
case 3:
printf("Goodbye!\n");
exit(0);
default:
printf("Invalid choice. Please try again.\n");
break;
}
}
return 0;
}
```
这个程序实现了一个简单的订餐系统,可以查看菜单、下订单并计算订单总价。界面通过命令行输出实现。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)