-
Notifications
You must be signed in to change notification settings - Fork 0
/
market.h
75 lines (61 loc) · 1.94 KB
/
market.h
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
double total;
int to_buy, to_sell, i;
bool unlocked = false;
void market() {
for (i = 0; i < 5; ++i) {
if (tier >= 11) {
printf("You have %zu %s, which you can sell for $%d per piece.\n", data[i], fish[i], sale[i]);
} else {
printf("You have %zu %s.\n", data[i], fish[i]);
}
}
if (tier >= 11) {
for (i = 7; i < 11; ++i) {
printf("You have %zu %s.\n", data[i-2], fish[i-1]);
}
}
printf("\n\nYou also have $%zu, and %zu bait.\n", money, bait);
total = floor((double) money / (double) COST);
if (tier >= 11) {
if (money >= COST) {
printf("\nYou can buy %g bait.\nHow much bait would you like to buy? ", total);
scanf("%d", &to_buy);
if (to_buy <= total) {
money -= to_buy * COST;
bait += to_buy;
unlocked = true;
} else {
printf("Unfortunately, you can't afford that much bait.\n\tEither try buying less, or try selling some of your fish.\n");
}
} else {
printf("You can't afford any bait. Bait costs $21 per piece. You currently have $%zu.\n", money);
}
}
/*for (i = 5, has_some = false; i < 9; ++i) {
if (data[i] != 0) {
has_some = true;
}
}*/
if (unlocked) {
printf("\nYou can now sell some of your less-valued fish.\n");
printf("What would you like to sell?\n");
for (i = 0; i < 5; ++i) {
printf("\tPress %d to sell %s,\n", i + 1, fish[i]);
}
printf("Or press 0 to not sell anything.\n> ");
scanf("%d", &choice);
if (choice > 0 && choice <= 5) {
printf("How much %s would you like to sell? (you currently have %zu) ", fish[choice - 1], data[choice - 1]);
scanf("%d", &to_sell);
if (to_sell > data[choice - 1]) {
printf("You don't have that much %s!\n", fish[choice - 1]);
return;
} else {
data[choice - 1] -= to_sell;
money += sale[choice - 1] * to_sell;
}
} else {
printf("Not selling anything.\n");
}
}
}