c语言饮料机售卖系统代码
时间: 2023-12-23 07:03:52 浏览: 82
使用qt开发的智能售货系统(饮料售卖机)。.zip
以下是一个简单的 C 语言饮料机售卖系统的代码实现:
```
#include <stdio.h>
int main() {
int choice, quantity;
float cost;
printf("*** Welcome to the Drink Vending Machine ***\n\n");
printf("1. Coke - $1.50\n");
printf("2. Sprite - $1.25\n");
printf("3. Water - $0.75\n");
printf("4. Exit\n\n");
printf("Please enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("You have selected Coke.\n");
cost = 1.5;
break;
case 2:
printf("You have selected Sprite.\n");
cost = 1.25;
break;
case 3:
printf("You have selected Water.\n");
cost = 0.75;
break;
case 4:
printf("Thank you for using the Drink Vending Machine.\n");
return 0;
default:
printf("Invalid choice.\n");
return 0;
}
printf("Please enter the quantity: ");
scanf("%d", &quantity);
if (quantity < 1) {
printf("Quantity cannot be less than 1.\n");
return 0;
}
printf("The total cost is: $%.2f\n", cost * quantity);
printf("Thank you for using the Drink Vending Machine.\n");
return 0;
}
```
这个代码实现了一个简单的饮料机售卖系统。当程序运行时,它会输出菜单,然后要求用户输入选择和数量。程序会计算出总成本并输出结果。如果用户输入了无效的选择或数量,程序会输出错误信息。
阅读全文