Plinko simulator!

Just a heads up, I'm going to be needing a lot of help! So we are making a program that simulates plinko. There is just a lof of styling that is making it a little difficult for me. Also we are doing it through an online textbook that is really picky and my numbers for the simulation arent the same one it should be. This is what i got...

should look like this

Welcome to the plinko simulator!

MENU: Please select one of the following options:

0 - Quit the program
1 - Drop a single chip into one slot
2 - Drop multiple chips into one slot

Enter your selection now: -1

INVALID SELECTION. Please enter 0, 1 or 2

MENU: Please select one of the following options:

0 - Quit the program
1 - Drop a single chip into one slot
2 - Drop multiple chips into one slot

Enter your selection now: 3

INVALID SELECTION. Please enter 0, 1 or 2

MENU: Please select one of the following options:

0 - Quit the program
1 - Drop a single chip into one slot
2 - Drop multiple chips into one slot

Enter your selection now: 1

*** DROP SINGLE CHIP ***

Which slot do you want to drop the chip in (0-8)? -1

INVALID SLOT.

MENU: Please select one of the following options:

0 - Quit the program
1 - Drop a single chip into one slot
2 - Drop multiple chips into one slot

Enter your selection now: 1

*** DROP SINGLE CHIP ***

Which slot do you want to drop the chip in (0-8)? 9

INVALID SLOT.

MENU: Please select one of the following options:

0 - Quit the program
1 - Drop a single chip into one slot
2 - Drop multiple chips into one slot

Enter your selection now: 1

*** DROP SINGLE CHIP ***

Which slot do you want to drop the chip in (0-8)? 5

*** DROPPING CHIP INTO SLOT 5 ***
PATH: [5.0 4.5 4.0 4.5 5.0 4.5 4.0 4.5 4.0 4.5 5.0 4.5 5.0]
WINNINGS: $0.00

MENU: Please select one of the following options:

0 - Quit the program
1 - Drop a single chip into one slot
2 - Drop multiple chips into one slot

Enter your selection now: 2

*** DROP MULTIPLE CHIPS ***

How many chips do you want to drop (>0)? -1

INVALID NUMBER OF CHIPS.

MENU: Please select one of the following options:

0 - Quit the program
1 - Drop a single chip into one slot
2 - Drop multiple chips into one slot

Enter your selection now: 2

*** DROP MULTIPLE CHIPS ***

How many chips do you want to drop (>0)? 142

Which slot do you want to drop the chip in (0-8)? 7

Total Winnings on 142 chips: 115100.00
Average winnings per chip: 810.56

MENU: Please select one of the following options:

0 - Quit the program
1 - Drop a single chip into one slot
2 - Drop multiple chips into one slot

Enter your selection now: 0

GOODBYE!

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
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main()
{
   cout << "Welcome to the plinko simulator!" << endl;
   cout << endl;
   
	int menu = 1;
	while (menu != 0)
	{
	   string menuChoice = "";
		cin >> menuChoice;
		int slotnumber = 0;
		int chipnumber = 0;
		double location = slotnumber;
		double reward = 0;
		srand(42);
		const double PRIZE_0= 100;
		const double PRIZE_1 = 500;
		const double PRIZE_2 = 1000;
		const double PRIZE_3 = 0;
		const double PRIZE_4 = 10000;
		const double PRIZE_5 = 0;
		const double PRIZE_6 = 1000;
		const double PRIZE_7 = 500;
		const double PRIZE_8 = 100;

		cout << "MENU: Please select one of the following options:"<< endl;
		cout << 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;
		cout << endl;
		cout << "Enter your selection now: " << endl;
		

	if (menuChoice == "1")// single chip
		{
		   cout << "*** DROP SINGLE CHIP ***" << endl;
		   cout << endl;
			cout << "Which slot do you want to drop the chip in (0-8)? ";
			cin >> slotnumber;
			cout << endl;
			cout <<"*** DROPPING CHIP INTO SLOT " << slotnumber << " ***" << endl; //rememmber to change variable names
			cout << "PATH: [";

			if (slotnumber >= 0 && slotnumber <= 8)
			{
				double location = slotnumber;
				cout << fixed << setprecision(1) << location << " ";
				for (int i = 0; i < 12; i++) 
				{
               int random_number = rand();
					double random = rand() % 2;
					if (random < 1)
					{
						location = location + 0.5;
					}
					else
					{
						location = location - 0.5;
					}
					if (location < 0)
					{
						location = 0.5;
					}
					else if (location > 8)
					{
						location = 7.5;
					}
					
					cout << location << " ";
				}

				if (location == 0){ reward = PRIZE_0; }
				else if (location == 1){ reward = PRIZE_1; }
				else if (location == 2){ reward = PRIZE_2; }
				else if (location == 3){ reward = PRIZE_3; }
				else if (location == 4){ reward = PRIZE_4; }
				else if (location == 5){ reward = PRIZE_5; }
				else if (location == 6){ reward = PRIZE_6; }
				else if (location == 7){ reward = PRIZE_7; }
				else if (location == 8){ reward = PRIZE_8; }

			}

         cout << "]" << endl;
			cout << fixed << setprecision(2) << "WINNINGS: $" << reward << endl;
			cout << endl;

		}

		else if (menuChoice == "2")// multiple chips options
		{
			cout << "Please enter the number of chips to drop: ";
			cin >> chipnumber;
			if (chipnumber > 0)
			{
				cout << "Please select a slot (0-8): ";
				cin >> slotnumber;

				if (slotnumber >= 0 && slotnumber <= 8)
				{

					double location = slotnumber;
					double totalwinnings = 0;


					for (int i = 0; i < chipnumber; i++)
					{
						/*cout << slotnumber << endl;*/
						totalwinnings = totalwinnings + reward;

						for (int i = 0; i < 12; i++) 
						{
							double random = rand() % 2;
							if (random < 1)
							{
								location = location + 0.5;
							}
							else
							{
								location = location - 0.5;
							}
							if (location < 0)
							{
								location = 0.5;
							}
							else if (location > 8)
							{
								location = 7.5;
							}
							/*cout << location << endl;
							cout << reward << endl;
							cout << totalwinnings << endl;*/
						}



						if (location == 0){ reward = 100; }
						else if (location == 1){ reward = 500; }
						else if (location == 2){ reward = 1000; }
						else if (location == 3){ reward = 0; }
						else if (location == 4){ reward = 10000; }
						else if (location == 5){ reward = 0; }
						else if (location == 6){ reward = 1000; }
						else if (location == 7){ reward = 500; }
						else if (location == 8){ reward = 100; }

						location = slotnumber;
					}
					double average = totalwinnings / chipnumber;// calculate total winnings for multiple chips
					cout << "Average winnings per chip: $" << average << endl;
					cout << "Total winnings: $" << totalwinnings << endl;
					cout << endl << endl << endl;

				}
			}
		}

		else if (menuChoice == "0")// quit option
		{
		   cout << "GOODBYE!";
			return 0;
		}
      else {
         cout << "INVALID SELECTION.  Please enter 0, 1 or 2" << endl;
         cout << endl;
      }

	}

	return 0;
}
Last edited on
Ok, I've ran the code.

There is one thing that I found weird and hard to navigate:
Why is it i get the intro and yet there is no prompt to tell me what to input I type any number and then it goes on and tells me my options but it runs as if I already selected my option. The weirdest part of that is it happens every single time.

Maybe a do {...} while (...) would fix it?

Other then that I haven't the slightest clue.

For instance this is my output:
Welcome to the plinko simulator!

1
MENU: Please select one of the following options:

0 - Quit the program
1 - Drop a single chip into one slot
2 - Drop multiple chips into one slot

Enter your selection now: 
*** DROP SINGLE CHIP ***

Which slot do you want to drop the chip in (0-8)? 0

*** DROPPING CHIP INTO SLOT 0 ***
PATH: [0.0 0.5 0.0 0.5 1.0 0.5 0.0 0.5 1.0 1.5 1.0 1.5 1.0 ]
WINNINGS: $500.00



1
MENU: Please select one of the following options:

0 - Quit the program
1 - Drop a single chip into one slot
2 - Drop multiple chips into one slot

Enter your selection now: 
*** DROP SINGLE CHIP ***

Which slot do you want to drop the chip in (0-8)? 0

*** DROPPING CHIP INTO SLOT 0 ***
PATH: [0.0 0.5 0.0 0.5 1.0 0.5 0.0 0.5 1.0 1.5 1.0 1.5 1.0 ]
WINNINGS: $500.00

0
MENU: Please select one of the following options:

0 - Quit the program
1 - Drop a single chip into one slot
2 - Drop multiple chips into one slot

Enter your selection now: 
GOODBYE! 
Exit code: 0 (normal program termination)


I hope that helps at least a little.

~ Hirokachi
Topic archived. No new replies allowed.