LAST PART OF PLINKO

I cant get my output to be 1000.00 instead of 1000

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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <stdlib.h>

using namespace std;

const double PRIZE_0 = 100.00;
const double PRIZE_1 = 500.00;
const double PRIZE_2 = 1000.00;
const double PRIZE_3 = 0.00;
const double PRIZE_4 = 10000.00;
const double PRIZE_5 = 0.00;
const double PRIZE_6 = 1000.00;
const double PRIZE_7 = 500.00;
const double PRIZE_8 = 100.00;
const int ROWS_OF_PEGS = 12;

int main()
{
	
	int menuChoice;
	srand(42);
	
   cout << "Welcome to the plinko simulator!" << endl << endl;
   cout << fixed << setprecision(2);
   
	do
	{
		cout << "MENU: Please select one of the following options:" << endl << endl;
		cout << "0 - Quit the program" << endl;
		cout << "1 - Drop a single chip into one slot" << endl;
		cout << "2 - Drop multiple chips into one slot" << endl << endl;
		cout << "Enter your selection now: " << endl;
		cin >> menuChoice;

		switch (menuChoice)
		{
		case 1:
			cout << "*** DROP SINGLE CHIP ***" << endl << endl;
			cout << "Which slot do you want to drop the chip in (0-8)? ";
			int slotNumber;
			cin >> slotNumber;
			if (slotNumber > 8 || slotNumber < 0)
				{
				   cout << endl;
					cout << "INVALID SLOT." <<endl << endl;
					break;
				}
			else
				{
					double slotNumberDouble = slotNumber;
					cout << fixed << setprecision(1);
					cout << endl;
					cout << "*** DROPPING CHIP INTO SLOT " << slotNumber << " ***";
					cout << endl;
					
					
					cout << "PATH: [" << slotNumberDouble;

					double chipLocation = slotNumber;
										
					for (int i = 0; i < ROWS_OF_PEGS; i++)
					{
						int randomNumber = rand();
						if (randomNumber % 2 == 1)
						{
							chipLocation += 0.5;
							if (chipLocation > 8)
							{
								chipLocation -= 1.0;
								cout << " " << chipLocation;
							}
							else
							{
								cout << " " << chipLocation;
							}
						}
						else
						{
							chipLocation -= 0.5;
							if (chipLocation < 0)
							{
								chipLocation += 1.0;
								cout << " " << chipLocation;
							}
							else
							{
								cout << " " << chipLocation;
							}
						}
					}

					cout << "]";
					
					int finalLocationChip2 = chipLocation;

					switch (finalLocationChip2)
					{
						case 0:
							finalLocationChip2 = PRIZE_0;
							break;
						case 1:
							finalLocationChip2 = PRIZE_1;
							break;
						case 2:
							finalLocationChip2 = PRIZE_2;
							break;
						case 3:
							finalLocationChip2 = PRIZE_3;
							break;
						case 4:
							finalLocationChip2 = PRIZE_4;
							break;
						case 5:
							finalLocationChip2 = PRIZE_5;
							break;
						case 6:
							finalLocationChip2 = PRIZE_6;
							break;
						case 7:
							finalLocationChip2 = PRIZE_7;
							break;
						case 8:
							finalLocationChip2 = PRIZE_8;
							break;
					}
					cout << fixed << setprecision(2);
					cout << "\nWINNINGS: $" << finalLocationChip2 << endl << endl;
				}
			break;

		case 2: 
			cout << "*** DROP MULTIPLE CHIPS ***"<< endl << endl;
			cout << "How many chips do you want to drop (>0)? " << endl;
			int chipNumber;
			cin >> chipNumber;
			if (chipNumber < 1)
			{
				cout << "INVALID NUMBER OF CHIPS." << endl << endl;
				break;
			}
			else
			{
				cout << "Which slot do you want to drop the chip in (0-8)? " << endl;
				int slotNumber2;
				cin >> slotNumber2;
				if (slotNumber2 > 8 || slotNumber2 < 0)
				{
					cout << "INVALID SLOT.";
					cout<< endl << endl;
					break;
				}
				else
				{
					double totalWinnings = 0;
					for (int i = 0; i < chipNumber; i++)
					{
						double chipLocation = slotNumber2;

						for (int i = 0; i < 12; i++)
						{
							int randomNumber = rand();
							if (randomNumber % 2 == 1)
							{
								chipLocation += 0.5;
								if (chipLocation > 8)
								{
									chipLocation -= 1.0;
								}
							}
							else
							{
								chipLocation -= 0.5;
								if (chipLocation < 0)
								{
									chipLocation += 1.0;
								}
							}

						}
						int finalLocationChip2 = chipLocation;

						switch (finalLocationChip2)
						{
						case 0:
							finalLocationChip2 = PRIZE_0;
							break;
						case 1:
							finalLocationChip2 = PRIZE_1;
							break;
						case 2:
							finalLocationChip2 = PRIZE_2;
							break;
						case 3:
							finalLocationChip2 = PRIZE_3;
							break;
						case 4:
							finalLocationChip2 = PRIZE_4;
							break;
						case 5:
							finalLocationChip2 = PRIZE_5;
							break;
						case 6:
							finalLocationChip2 = PRIZE_6;
							break;
						case 7:
							finalLocationChip2 = PRIZE_7;
							break;
						case 8:
							finalLocationChip2 = PRIZE_8;
							break;
						}

						totalWinnings += finalLocationChip2;
					}
						cout << fixed << setprecision(2);
						cout << "Total Winnings on " << chipNumber << " chips: " << totalWinnings << endl;
						double averageWinningsPerChip = totalWinnings / chipNumber;
						cout << "Average winnings per chip: " << averageWinningsPerChip << endl << endl;
				}
			}
				break;
		case 0: 
			cout << "GOODBYE!";
			//system("pause");
			return 0;
			break;
		default:
			cout << "INVALID SELECTION.  Please enter 0, 1 or 2" << endl << endl;
			break;
		}
	} while (true);
	//system("pause");
	return 0;
}
Last edited on
I cant get my output to be 1000.00 instead of 1000


You can use :
1
2
3
cout << "Welcome to the plinko simulator!" << endl << endl;
cout.setf(ios::fixed);
cout.precision(2);

No it still does 1000
What is the line that outputs 1000?
214
Last edited on
Am I wrong? In the line 214 :
finalLocationChip2 = PRIZE_8;
There is no cout statement.
It is after case 8
1
2
3
cout << "Total Winnings on " << (double) chipNumber << " chips: " << (double) totalWinnings << endl;
double averageWinningsPerChip = totalWinnings / chipNumber;
cout << "Average winnings per chip: " << averageWinningsPerChip << endl << endl;
That one is for the multiple chips, it won't work on the single chip part
1
2
cout << fixed << setprecision(2);
cout << "\nWINNINGS: $" << (double) finalLocationChip2 << endl << endl;
bless you! honestly you are the #1 in my book!!! THANKS THANKS!
Topic archived. No new replies allowed.