简单的旅游景点售票系统C语言代码
时间: 2023-10-09 20:04:28 浏览: 66
以下是一个简单的旅游景点售票系统的 C 语言代码:
```c
#include <stdio.h>
int main() {
int choice, num_tickets;
float price, total;
printf("Welcome to XYZ Tourist Attraction!\n");
printf("Please select a package:\n");
printf("1. Basic package - $10.00 per ticket\n");
printf("2. Premium package - $20.00 per ticket\n");
printf("3. VIP package - $50.00 per ticket\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1:
price = 10.00;
printf("You have selected the Basic package.\n");
break;
case 2:
price = 20.00;
printf("You have selected the Premium package.\n");
break;
case 3:
price = 50.00;
printf("You have selected the VIP package.\n");
break;
default:
printf("Invalid choice. Please try again.\n");
return 0;
}
printf("How many tickets would you like to purchase? ");
scanf("%d", &num_tickets);
total = price * num_tickets;
printf("You have purchased %d tickets at $%.2f each.\n", num_tickets, price);
printf("Your total cost is $%.2f.\n", total);
return 0;
}
```
该代码首先打印欢迎信息和不同套餐的价格,然后要求用户输入他们的选择。接下来,使用 switch 语句确定所选套餐的价格,并要求用户输入购买的票数。最后,计算总价格并打印出来。
阅读全文