-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·177 lines (166 loc) · 5.05 KB
/
main.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ios>
#include<iomanip>
using namespace std;
int main() {
const double SLOT_ZERO = 100;
const double SLOT_ONE = 500;
const double SLOT_TWO = 1000;
const double SLOT_THREE = 0;
const double SLOT_FOUR = 10000;
int menuSelect;
double slotValue;
double dropValue;
int startingSlot;
int numChips;
double totalWinnings = 0.0;
const int RANDOM_SEED = 42;
srand(RANDOM_SEED);
//Part 1
cout << "Welcome to the Plinko simulator! Enter 3 to see options." << endl << endl << "Enter your selection now: ";
cin >> menuSelect;
while (menuSelect != 4) {
//Part 2
if (menuSelect == 1) {
cout << endl << "*** Drop a single chip ***" << endl << endl;
cout << "Which slot do you want to drop the chip in (0-8)? ";
cin >> slotValue;
if ((slotValue >= 0) && (slotValue <= 8)) {
cout << fixed << endl << "*** Dropping chip into slot " << static_cast<int>(slotValue) << " ***" << endl;
cout << "Path: [" << setprecision(1) << slotValue << ", ";
for (int i = 0; i < 11; ++i) {
if (slotValue == 0) {
slotValue = slotValue + 0.5;
cout << setprecision(1) << slotValue << ", ";
}
else if (slotValue == 8) {
slotValue = slotValue - 0.5;
cout << setprecision(1) << slotValue << ", ";
}
else {
dropValue = rand() % 2;
if (dropValue == 0) {
slotValue = slotValue - 0.5;
cout << setprecision(1) << slotValue << ", ";
}
else if (dropValue == 1) {
slotValue = slotValue + 0.5;
cout << setprecision(1) << slotValue << ", ";
}
}
}
if (slotValue == 0) {
slotValue = slotValue + 0.5;
cout << setprecision(1) << slotValue << "]" << endl;
}
else if (slotValue == 8) {
slotValue = slotValue - 0.5;
cout << setprecision(1) << slotValue << "]" << endl;
}
else {
dropValue = rand() % 2;
if (dropValue == 0) {
slotValue = slotValue - 0.5;
cout << setprecision(1) << slotValue << "]" << endl;
}
else if (dropValue == 1) {
slotValue = slotValue + 0.5;
cout << setprecision(1) << slotValue << "]" << endl;
}
}
cout << "Winnings: $";
if ((slotValue == 0) || (slotValue == 8)) {
cout << setprecision(2) << SLOT_ZERO << endl;
}
else if ((slotValue == 1) || (slotValue == 7)) {
cout << setprecision(2) << SLOT_ONE << endl;
}
else if ((slotValue == 2) || (slotValue == 6)) {
cout << setprecision(2) << SLOT_TWO << endl;
}
else if ((slotValue == 3) || (slotValue == 5)) {
cout << setprecision(2) << SLOT_THREE << endl;
}
else {
cout << setprecision(2) << SLOT_FOUR << endl;
}
}
else {
cout << endl << "Invalid slot." << endl;
}
}
//Part 3
else if (menuSelect == 2) {
cout << endl << "*** Drop multiple chips ***" << endl << endl;
cout << "How many chips do you want to drop(> 0) ? ";
cin >> numChips;
if (numChips > 0) {
cout << endl << "Which slot do you want to drop the chip in (0-8)? ";
cin >> startingSlot;
slotValue = startingSlot;
totalWinnings = 0;
if ((startingSlot >= 0) && (startingSlot <= 8)) {
for (int i = 0; i < numChips; ++i) {
slotValue = startingSlot;
for (int j = 0; j < 12; ++j) {
if (slotValue == 0) {
slotValue = slotValue + 0.5;
}
else if (slotValue == 8) {
slotValue = slotValue - 0.5;
}
else {
dropValue = rand() % 2;
if (dropValue == 0) {
slotValue = slotValue - 0.5;
}
else if (dropValue == 1) {
slotValue = slotValue + 0.5;
}
}
}
if ((slotValue == 0) || (slotValue == 8)) {
totalWinnings = totalWinnings + SLOT_ZERO;
}
else if ((slotValue == 1) || (slotValue == 7)) {
totalWinnings = totalWinnings + SLOT_ONE;
}
else if ((slotValue == 2) || (slotValue == 6)) {
totalWinnings = totalWinnings + SLOT_TWO;
}
else if ((slotValue == 3) || (slotValue == 5)) {
totalWinnings = totalWinnings + SLOT_THREE;
}
else {
totalWinnings = totalWinnings + SLOT_FOUR;
}
}
cout << endl << "Total winnings on " << numChips << " chips: $" << fixed << setprecision(2) << totalWinnings << endl;
cout << "Average winnings per chip: $" << setprecision(2) << (totalWinnings / numChips) << endl;
}
else {
cout << endl << "Invalid slot." << endl;
}
}
else {
cout << endl << "Invalid number of chips." << endl;
}
}
else if (menuSelect == 3) {
cout << endl << "Menu: Please select one of the following options:" << endl << endl;
cout << "1 - Drop a single chip into one slot" << endl;
cout << "2 - Drop multiple chips into one slot" << endl;
cout << "3 - Show the options menu" << endl;
cout << "4 - Quit the program" << endl << endl;
}
else if ((menuSelect < 1) || (menuSelect > 4)) {
cout << endl << "Invalid selection. Enter 3 to see options." << endl;
}
cout << endl << "Enter your selection now: ";
cin >> menuSelect;
}
cout << endl << "Goodbye!";
return 0;
}