C语言点菜机系统框架
以下是一个简单的点菜机系统的C语言框架:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char name[50];
float price;
} Dish;
void displayMenu(Dish menu[], int size) {
printf("======= Menu =======\n");
for (int i = 0; i < size; i++) {
printf("%d. %s ($%.2f)\n", i+1, menu[i].name, menu[i].price);
}
printf("====================\n");
}
void placeOrder(Dish menu[], int size) {
int choice, quantity;
float total = 0.0;
printf("Enter the dish number (0 to finish order): ");
scanf("%d", &choice);
while (choice != 0) {
printf("Enter the quantity: ");
scanf("%d", &quantity);
total += menu[choice-1].price * quantity;
printf("Enter the dish number (0 to finish order): ");
scanf("%d", &choice);
}
printf("Total amount: $%.2f\n", total);
}
int main() {
Dish menu[5] = {{"Dish 1", 10.0}, {"Dish 2", 15.0}, {"Dish 3", 12.0}, {"Dish 4", 8.0}, {"Dish 5", 20.0}};
int size = sizeof(menu) / sizeof(menu[0]);
displayMenu(menu, size);
placeOrder(menu, size);
return 0;
}
这个框架定义了一个Dish结构体来表示菜品,包含了菜名和价格两个字段。displayMenu函数用于显示菜单,它遍历菜单数组并打印出每个菜品的编号、菜名和价格。placeOrder函数用于点菜,它让用户输入菜品编号和数量,然后计算总金额。main函数初始化了一个菜单数组,并调用displayMenu和placeOrder函数来展示菜单和点菜。
你可以根据具体需求进行修改和扩展这个框架
原文地址: https://www.cveoy.top/t/topic/iMu9 著作权归作者所有。请勿转载和采集!