-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlinko_simulator_game.cpp
189 lines (178 loc) · 4.23 KB
/
Plinko_simulator_game.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
178
179
180
181
182
183
184
185
186
187
188
189
/*
Matthew Steffen and Jordan Holbrook
Programmed by Pair Programming
Section 006
Programmed in Visual Studio
Test case 1:
Input:
3 1 5 4
Result:
Test case 2:
Input:
3 2 27 8 4
Result: Passed, Tested to see if large number of chips would work
Test case 3:
3 -1 57 2 5 15 1 15 4 //Destined to fail every time.
*/
#include <iostream>
#include <string>
#include <random>
#include <iomanip>
using namespace std;
int main() {
//Variables to use
int option, prob, chips;
double winnings, total, place, slot;
bool quit = true;
const int RANDOM_SEED = 42;
srand(RANDOM_SEED);
winnings = 0.0;
total = 0.0;
//Constants for score
const double SLOT0 = 100.0;
const double SLOT1 = 500.0;
const double SLOT2 = 1000.0;
const double SLOT3 = 0.0;
const double SLOT4 = 10000.0;
const double SLOT5 = 0.0;
const double SLOT6 = 1000.0;
const double SLOT7 = 500.0;
const double SLOT8 = 100.0;
//Beginning
cout << "Welcome to the Plinko Simulator! Enter 3 to see options." << endl;
cout << endl;
while (quit) {
cout << "Enter your selection now:" << endl;
cin >> option;
cout << endl;
switch (option) {
case 1:
cout << "*** Drop a single chip ***"<< endl << endl;
cout << "Which slot do you want to drop the chip in (0-8)?" << endl;
cin >> place;
if (place < 0 || place >= 9) {
cout << "Invalid slot." << endl;
break;
}
else {
cout << "*** Dropping chip into slot " << (int)place << " ***" << endl << endl;
cout << "Path: [" << fixed << setprecision(1) << place;
for (int x = 0; x < 12; ++x) {
if (x < 12)
cout << ", ";
if (place == 0 || place == 8) {
if (place == 0)
place += 0.5;
else
place -= 0.5;
}
else {
prob = rand() % 2;
if (prob == 0)
place -= 0.5;
else
place += 0.5;
}
cout << fixed << setprecision(1) << place;
}
cout << ']' << endl;
switch ((int)place) {
case 0: winnings = SLOT0;
break;
case 1: winnings = SLOT1;
break;
case 2: winnings = SLOT2;
break;
case 3: winnings = SLOT3;
break;
case 4: winnings = SLOT4;
break;
case 5: winnings = SLOT5;
break;
case 6: winnings = SLOT6;
break;
case 7: winnings = SLOT7;
break;
case 8: winnings = SLOT8;
break;
}
cout << fixed << setprecision(2);
cout << "Winnings: $" << winnings << endl;
break;
case 2:
total = 0.0;
cout << "*** Drop multiple chips ***" << endl;
cout << "How many chips do you want to drop (>0)?" << endl << endl;
cin >> chips;
if (chips <= 0) {
cout << "Invalid number of chips." << endl;
break;
}
cout << "Which slot do you want to drop the chip in (0-8)?" << endl << endl;
cin >> slot;
if (slot < 0 || slot >= 9) {
cout << "Invalid slot." << endl;
break;
}
//Calculate the total winnings
//for (how many chips) for (path)
place = slot;
for (int x = 0; x < chips; ++x) {
place = slot;
for (int y = 0; y < 12; ++y) {
if (place == 0 || place == 8) {
if (place == 0)
place += 0.5;
else
place -= 0.5;
}
else {
prob = rand() % 2;
if (prob == 0)
place -= 0.5;
else
place += 0.5;
}
}
switch ((int)place) {
case 0: winnings = SLOT0;
break;
case 1: winnings = SLOT1;
break;
case 2: winnings = SLOT2;
break;
case 3: winnings = SLOT3;
break;
case 4: winnings = SLOT4;
break;
case 5: winnings = SLOT5;
break;
case 6: winnings = SLOT6;
break;
case 7: winnings = SLOT7;
break;
case 8: winnings = SLOT8;
break;
}
total += winnings;
}
}
cout << fixed << setprecision(2);
cout << "Total winnings on " << chips << " chips: $" << total << endl;
cout << "Average winnings per chip: $" << total / (double)chips << endl;
break;
case 3:
cout << "Menu: Please select one of the following options:\n\n1 - Drop a single chip into one slot\n2 - Drop multiple chips into one slot\n3 - Show the options menu\n4 - Quit the program\n";
break;
case 4:
quit = false;
cout << "Goodbye!";
break;
default:
cout << "Invalid Selection. Enter 3 to see options." << endl;
break;
}
}
return 0;
}