-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbca-mart.c
More file actions
100 lines (88 loc) · 2.98 KB
/
bca-mart.c
File metadata and controls
100 lines (88 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <stdlib.h>
int money = 15;
int purchase(char *item, int cost) {
int amount;
printf("How many %s would you like to buy?\n", item);
printf("> ");
scanf("%d", &amount);
if (amount > 0) {
cost *= amount;
printf("That'll cost $%d.\n", cost);
if (cost <= money) {
puts("Thanks for your purchse!");
money -= cost;
} else {
puts("Sorry, but you don't have enough money.");
puts("Sucks to be you I guess.");
amount = 0;
}
} else {
puts("I'm sorry, but we don't put up with pranksters.");
puts("Please buy something or leave.");
}
return amount;
}
int main() {
int input;
setbuf(stdout, NULL);
setbuf(stdin, NULL);
setbuf(stderr, NULL);
puts("Welcome to BCA MART!");
puts("We have tons of snacks available for purchase.");
puts("(Please ignore the fact we charge a markup on everything)");
while (1) {
puts("");
puts("1) Hichew™: $2.00");
puts("2) Lays® Potato Chips: $2.00");
puts("3) Water in a Bottle: $1.00");
puts("4) Not Water© in a Bottle: $2.00");
puts("5) BCA© school merch: $20.00");
puts("6) Flag: $100.00");
puts("0) Leave");
puts("");
printf("You currently have $%d.\n", money);
puts("What would you like to buy?");
printf("> ");
scanf("%d", &input);
switch (input) {
case 0:
puts("Goodbye!");
puts("Come back soon!");
puts("Obviously, to spend more money :)");
return 0;
case 1:
purchase("fruity pieces of goodness", 2);
break;
case 2:
purchase("b̶a̶g̶s̶ ̶o̶f̶ ̶a̶i̶r̶ potato chips", 2);
break;
case 3:
purchase("bottles of tap water", 1);
break;
case 4:
purchase("generic carbonated beverages", 2);
break;
case 5:
purchase("wonderfully-designed t-shirts", 20);
break;
case 6:
if (purchase("super-cool ctf flags", 100) > 0) {
FILE *fp = fopen("flag.txt", "r");
char flag[100];
if (fp == NULL) {
puts("Hmm, I can't open our flag.txt file.");
puts("Sorry, but looks like we're all out of flags.");
puts("Out of luck, we just sold our last one a couple mintues ago.");
puts("[If you are seeing this on the remote server, please contact admin].");
exit(1);
}
fgets(flag, sizeof(flag), fp);
puts(flag);
}
break;
default:
puts("Sorry, please select a valid option.");
}
}
}