简单的旅游景点售票系统C语言代码
时间: 2023-10-09 20:04:28 浏览: 115
以下是一个简单的旅游景点售票系统C语言代码,可以作为参考:
```c
#include <stdio.h>
int main() {
int choice, quantity, price, total_price;
printf("Welcome to the Travel Agency!\n");
printf("Please choose a destination:\n");
printf("1. Beijing - $100 per ticket\n");
printf("2. Shanghai - $80 per ticket\n");
printf("3. Guangzhou - $50 per ticket\n");
printf("4. Shenzhen - $60 per ticket\n");
printf("Enter your choice (1-4): ");
scanf("%d", &choice);
switch (choice) {
case 1:
price = 100;
printf("You selected Beijing. The ticket price is $%d.\n", price);
break;
case 2:
price = 80;
printf("You selected Shanghai. The ticket price is $%d.\n", price);
break;
case 3:
price = 50;
printf("You selected Guangzhou. The ticket price is $%d.\n", price);
break;
case 4:
price = 60;
printf("You selected Shenzhen. The ticket price is $%d.\n", price);
break;
default:
printf("Invalid choice.\n");
return 0;
}
printf("How many tickets do you want to buy? ");
scanf("%d", &quantity);
total_price = price * quantity;
printf("You selected %d tickets. The total price is $%d.\n", quantity, total_price);
printf("Thank you for choosing the Travel Agency!\n");
return 0;
}
```
以上代码实现了一个简单的旅游景点售票系统,用户可以选择想要购买的目的地和数量,程序会计算出总价并输出。
阅读全文