Plinko w/Functions

Can someone help me refactor my original code to *include functions*. It's a Plinko simulator. I am a beginner, pretty awful at coding, and do not enjoy it so much. I understand the basics of C++ (and the basics of functions), and for the most part can describe what a compiler is doing throughout a code, but when it comes time for myself to construct a much bigger program it is too much. Any help or advice would be GREATLY appreciated.

Here is the original code WITHOUT functions:

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
#include<iostream>
#include<iomanip>
#include <cstdlib>
using namespace std;

int main() {
   int menuChoice = 0;
	int slotChoice = 0;
	const int RAND_SEED = 42;
	double slot = 0.0;
	int i = 0;
	int j = 0;
	int randNum = 0;
	const int MONEY_PRECISION = 2;
	const int SLOT_PRECISION = 1;
	double prizeMoney = 0.0;
	int multiDropNum = 0;
	const double SINGLE_SLOT_MOVE = 0.5;
	const int SINGLE_DROP_CHOICE = 1;       
	const int MULTI_DROP_CHOICE = 2;
	const int DISPLAY_MENU_CHOICE = 3; 
	const int QUIT_PROGRAM_CHOICE = 4;
	double totalWinnings = 0.0;
	const int NUM_ROWS = 12;
	const double SMALL_PRIZE = 100.0;
	const double MEDIUM_PRIZE = 500.0;
	const double LARGE_PRIZE = 1000.0;
	const double NO_PRIZE = 0.0;
	const double GIANT_PRIZE = 10000.0;
	const int HIGHEST_SLOT = 8;
	const int MIN_CHIP_NUM = 0;
	const int LOWEST_SLOT = 0;
	const int PATH_OUTPUT_CHECKER = 11;
	const int WINNINGS_RESET = 0;
	const int SLOT_INCREMENT = 1;
	const int SLOT_DECREMENT = 0;


	srand(RAND_SEED);

	cout << "Welcome to the Plinko simulator!  Enter 3 to see options." << endl << endl;
	do {                    
		cout << "Enter your selection now: ";
		cin >> menuChoice;
		cout << endl;
		if (menuChoice == SINGLE_DROP_CHOICE) {
			cout << "*** Drop a single chip ***" << endl << endl;       
			cout << "Which slot do you want to drop the chip in(" << LOWEST_SLOT << " - " << HIGHEST_SLOT << ") ?" << endl;
			cin >> slotChoice;

			if ((slotChoice < LOWEST_SLOT) || (slotChoice > HIGHEST_SLOT)) {     
				cout << "Invalid slot." << endl << endl;
			}
			else {
				cout << fixed;             
				cout << "*** Dropping chip into slot " << slotChoice << " ***" << endl;
				slot = static_cast<double>(slotChoice);
				cout << fixed << setprecision(SLOT_PRECISION) << "Path: [" << slot << ", ";
				for (i = 0; i < NUM_ROWS; ++i) {

					if (slot == LOWEST_SLOT) {       
						slot = slot + SINGLE_SLOT_MOVE;
					}

					else if (slot == HIGHEST_SLOT) {    
						slot = slot - SINGLE_SLOT_MOVE;
					}

					else if ((slot > LOWEST_SLOT) && (slot < HIGHEST_SLOT)) {
						randNum = rand() % 2;               
						if (randNum == SLOT_INCREMENT) {
							slot = slot + SINGLE_SLOT_MOVE;
						}
						else {							
							slot = slot - SINGLE_SLOT_MOVE;
						}
					}

					if (i == PATH_OUTPUT_CHECKER) {
						cout << fixed << setprecision(SLOT_PRECISION) << slot << "]" << endl;
					}
					else {
						cout << fixed << setprecision(SLOT_PRECISION) << slot << ", ";
					}
				}
				switch (static_cast<int>(slot)) { 

				case 0:
					prizeMoney = SMALL_PRIZE;
					break;

				case 1:
					prizeMoney = MEDIUM_PRIZE;
					break;

				case 2:
					prizeMoney = LARGE_PRIZE;
					break;

				case 3:
					prizeMoney = NO_PRIZE;
					break;

				case 4:
					prizeMoney = GIANT_PRIZE;
					break;

				case 5:
					prizeMoney = NO_PRIZE;
					break;

				case 6:
					prizeMoney = LARGE_PRIZE;
					break;

				case 7:
					prizeMoney = MEDIUM_PRIZE;
					break;

				case 8:
					prizeMoney = SMALL_PRIZE;
					break;
				}
				cout << fixed << setprecision(MONEY_PRECISION) << "Winnings: $" << prizeMoney << endl << endl; 
			}
		}
		if (menuChoice == MULTI_DROP_CHOICE) {
			cout << "*** Drop multiple chips *** " << endl << endl;
			cout << "How many chips do you want to drop (>" << MIN_CHIP_NUM << ")? " << endl << endl;
			cin >> multiDropNum;

			if (multiDropNum <= MIN_CHIP_NUM) {
				cout << "Invalid number of chips.";
			}
			else {
				cout << "Which slot do you want to drop the chip in(" << LOWEST_SLOT << " - " << HIGHEST_SLOT << ") ?" << endl << endl;
				cin >> slotChoice;
				if ((slotChoice < LOWEST_SLOT) || (slotChoice > HIGHEST_SLOT)) {
					cout << "Invalid slot." << endl << endl;
				}
				else {
					for (j = 0; j < multiDropNum; ++j) {
						slot = slotChoice;
						for (i = 0; i < NUM_ROWS; ++i) {

							if (slot == LOWEST_SLOT) {  
								slot = slot + SINGLE_SLOT_MOVE;
							}

							else if (slot == HIGHEST_SLOT) {
								slot = slot - SINGLE_SLOT_MOVE;
							}

							else if ((slot > LOWEST_SLOT) && (slot < HIGHEST_SLOT)) {
								randNum = rand() % 2;
								if (randNum == SLOT_INCREMENT) {
									slot = slot + SINGLE_SLOT_MOVE;
								}
								else if (randNum == SLOT_DECREMENT) {
									slot = slot - SINGLE_SLOT_MOVE;
								}
							}

						}

						switch (static_cast<int>(slot)) { 

						case 0:
							prizeMoney = SMALL_PRIZE;
							break;

						case 1:
							prizeMoney = MEDIUM_PRIZE;
							break;

						case 2:
							prizeMoney = LARGE_PRIZE;
							break;

						case 3:
							prizeMoney = NO_PRIZE;
							break;

						case 4:
							prizeMoney = GIANT_PRIZE;
							break;

						case 5:
							prizeMoney = NO_PRIZE;
							break;

						case 6:
							prizeMoney = LARGE_PRIZE;
							break;

						case 7:
							prizeMoney = MEDIUM_PRIZE;
							break;

						case 8:
							prizeMoney = SMALL_PRIZE;
							break;
						}
						totalWinnings = totalWinnings + prizeMoney;     
					}
					cout << "Total winnings on " << multiDropNum << " chips: $" << fixed << setprecision(MONEY_PRECISION)
						<< totalWinnings << endl;
					cout << "Average winnings per chip : $" << totalWinnings / multiDropNum << endl << endl;
				}
				totalWinnings = WINNINGS_RESET;
			}



		}
		if (menuChoice == DISPLAY_MENU_CHOICE) {
			cout << "Menu: Please select one of the following options:" << endl << endl;     
			cout << SINGLE_DROP_CHOICE << " - Drop a single chip into one slot" << endl;
			cout << MULTI_DROP_CHOICE << " - Drop multiple chips into one slot" << endl;
			cout << DISPLAY_MENU_CHOICE << " - Show the options menu" << endl;
			cout << QUIT_PROGRAM_CHOICE << " - Quit the program" << endl;
		}
		if (menuChoice == QUIT_PROGRAM_CHOICE) {
			break;
		}
		if (menuChoice < SINGLE_DROP_CHOICE || menuChoice > QUIT_PROGRAM_CHOICE) {
			cout << "Invalid selection. Enter 3 to see options. " << endl << endl;   
		}

	} while (menuChoice != QUIT_PROGRAM_CHOICE);     

	cout << "Goodbye!";

        system("PAUSE");      

	return 0;
}
Last edited on
These are the instructions:

Part 1 - Refactoring

Computing the amount of prize money won for a single chip given the slot the chip ended up in-- this function must be defined as "double ComputeWinnings(int slot) {... your code here ...}. (See the original Plinko lab for the complete list of these values). If you have not declared and named this function exactly as specified you will no pass the initial unit tests in auto-grade which just test this function. Also, this time we want you to represent the winnings as a constant so that it would be easy to create a new Plinko board by just changing the constant. Hint: Think of using a constant array of values to represent the winnings for each slot.

Simulating one chip falling-- you will have to use your discretion on how you name and code this, but it should make both the "Drop a single chip into one slot" option and the next function (Simulating multiple chips falling) easier to write. This function must make use of the "ComputeWinnings" function described above.

Simulating multiple chips falling-- similarly this function should make both the "Drop multiple chips into one slot" option and a new "Drop multiple chips into each slot" option (described below) easier to write. This function must make use of the "Simulating one chip falling" function described above.

Add a new menu item for "Drop multiple chips into each slot", but you do not have to implement it yet. You will implement it in Part 3.

We will update the error handling in Part 2, so for Part 1, you may assume that there will be no input errors.

Part 2 - Better Error Handling

Add a function for getting the number of chips and a function for getting the slot number. Within these functions check for user input error and reprompt until the user provides valid input. You must be able to recognize erroneous input like "-1", "x", "Not even a number", and in the case of a slot number, invalid integers like "9". You may assume that there will be no real-valued inputs like "2.3". Add a function for getting the menu option also, reprompting if an erroneous option is input.

If you think about it for a minute you will realize that you could use a single function rather than three separate functions for inputting a correct integer. Obviously it would need additional parameters to work as required in each case, but it is a better approach. We encourage you to do it with just one function. More general functions like this have the advantage of being re-usable in later programs which need an integer input, rather than having to write a new function for each specific variation on inputting an integer.

Part 3 - Functions and the Power of Code Reuse

In this part of the lab, you will take advantage of functions to add an additional menu option to your Plinko program, without having to duplicate code from the other menu options.

--Add a new menu option 3 that allows the user to drop the same number of chips into each of the 9 slots. For example, if the user enters 5, you simulate dropping 5 chips into each of the 9 slots.
--Prompt the user to enter one number, which is the number of chips to drop into every slot. If the number of chips is non-positive or a string, etc., re-prompt until you get valid input (hint: just use the function you wrote in Part 2)
--For each slot, report the total and average amount of money won for all chips dropped into that slot.

Hint: You should be able to write this new option easily by just using functions you have already created. No new functions should be necessary. Also, try this option with a large number of chips (try a million) and you will see which slots really are best on average. See if you can notice a type of "Bell curve."
Hello heythere17,

I am a beginner, pretty awful at coding, and do not enjoy it so much. I understand the basics of C++ (and the basics of functions), and for the most part can describe what a compiler is doing throughout a code, but when it comes time for myself to construct a much bigger program it is too much.

Watch what you say. This tends to imply that you are not interested and want someone to do the work for you. There are many good people here that are willing to help you understand what you did wrong, but few if any willing to do your homework for you.

That said take a look at part 1 this way:
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
Part 1 - Refactoring

Computing the amount of prize money won for a single chip given the slot the chip ended up in--

this function must be defined as "double ComputeWinnings(int slot) {... your code here ...}.

(See the original Plinko lab for the complete list of these values). If you have not declared and named this
function exactly as specified you will not pass the initial unit tests in auto-grade which just test this
function.

Also, this time we want you to represent the winnings as a constant so that it would be easy to
create a new Plinko board by just changing the constant.

Hint: Think of using a constant array of values to represent the winnings for each slot.

Simulating one chip falling-- you will have to use your discretion on how you name and code this, but it should
make both the "Drop a single chip into one slot" option and the next function (Simulating multiple chips falling)
easier to write. This function must make use of the "ComputeWinnings" function described above.

Simulating multiple chips falling-- similarly this function should make both the "Drop multiple chips into one
slot" option and a new "Drop multiple chips into each slot" option (described below) easier to write. This
function must make use of the "Simulating one chip falling" function described above.

Add a new menu item for "Drop multiple chips into each slot", but you do not have to implement it yet. You will
implement it in Part 3.

We will update the error handling in Part 2, so for Part 1, you may assume that there will be no input errors. 


Start with lines 3 and 5 first. It tells you everything you need to know to get started. Then look at the code you have and see what part(s) match what the function is to do. Hint any code repeated more than once is good candidate for a function.

Lines 11 and 12 along with line 14 go together part of which you have already done.

I will suggest this for you:
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
const int RAND_SEED = 42;
const int MONEY_PRECISION = 2;
const int SLOT_PRECISION = 1;
const double SINGLE_SLOT_MOVE = 0.5;
const int SINGLE_DROP_CHOICE = 1;
const int MULTI_DROP_CHOICE = 2;
const int DISPLAY_MENU_CHOICE = 3;
const int QUIT_PROGRAM_CHOICE = 4;
double totalWinnings = 0.0;
const int NUM_ROWS = 12;

const double SMALL_PRIZE = 100.0;
const double MEDIUM_PRIZE = 500.0;
const double LARGE_PRIZE = 1000.0;
const double NO_PRIZE = 0.0;
const double GIANT_PRIZE = 10000.0;

const int HIGHEST_SLOT = 8;
const int MIN_CHIP_NUM = 0;
const int LOWEST_SLOT = 0;
const int PATH_OUTPUT_CHECKER = 11;
const int WINNINGS_RESET = 0;
const int SLOT_INCREMENT = 1;
const int SLOT_DECREMENT = 0;

int menuChoice = 0;
int slotChoice = 0;
double slot = 0.0;
int i = 0;
int j = 0;
int randNum = 0;
double prizeMoney = 0.0;
int multiDropNum = 0;

Keep things that are alike together, so it is easier to find. And putting the "const" variables at the top makes it easier to change if you need to.

Now work something up and post it then we can work from there.

Hope that helps,

Andy
Handy Andy:

Everything is the same, but I called the function ComputeWinnings and executed as you can see below. I think next I need to call a function for dropping one chip into one slot, multiple chips into one slot, and multiple chips into each slot. Is the way to do this similar? Should I wait to call the function for "multiple chips into each slot"?

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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#include<iostream>
#include<iomanip>
#include <cstdlib>
using namespace std;


double ComputeWinnings(int slot) {
	const double SMALL_PRIZE = 100.0;
	const double MEDIUM_PRIZE = 500.0;
	const double LARGE_PRIZE = 1000.0;
	const double NO_PRIZE = 0.0;
	const double GIANT_PRIZE = 10000.0;
	double prizeMoney = 0.0;
	const int MONEY_PRECISION = 2;
	switch (static_cast<int>(slot)) {

	case 0:
		prizeMoney = SMALL_PRIZE;
		break;

	case 1:
		prizeMoney = MEDIUM_PRIZE;
		break;

	case 2:
		prizeMoney = LARGE_PRIZE;
		break;

	case 3:
		prizeMoney = NO_PRIZE;
		break;

	case 4:
		prizeMoney = GIANT_PRIZE;
		break;

	case 5:
		prizeMoney = NO_PRIZE;
		break;

	case 6:
		prizeMoney = LARGE_PRIZE;
		break;

	case 7:
		prizeMoney = MEDIUM_PRIZE;
		break;

	case 8:
		prizeMoney = SMALL_PRIZE;
		break;
	}
	
	return prizeMoney;
}






int main() {
	int menuChoice = 0;
	int slotChoice = 0;
	const int RAND_SEED = 42;
	double slot = 0.0;
	int i = 0;
	int j = 0;
	int randNum = 0;
	const int MONEY_PRECISION = 2;
	const int SLOT_PRECISION = 1;
	double prizeMoney = 0.0;
	int multiDropNum = 0;
	const double SINGLE_SLOT_MOVE = 0.5;
	const int SINGLE_DROP_CHOICE = 1;
	const int MULTI_DROP_CHOICE = 2;
	const int DISPLAY_MENU_CHOICE = 3;
	const int QUIT_PROGRAM_CHOICE = 4;
	double totalWinnings = 0.0;
	const int NUM_ROWS = 12;
	const double SMALL_PRIZE = 100.0;
	const double MEDIUM_PRIZE = 500.0;
	const double LARGE_PRIZE = 1000.0;
	const double NO_PRIZE = 0.0;
	const double GIANT_PRIZE = 10000.0;	
	const int HIGHEST_SLOT = 8;
	const int MIN_CHIP_NUM = 0;
	const int LOWEST_SLOT = 0;
	const int PATH_OUTPUT_CHECKER = 11;
	const int WINNINGS_RESET = 0;
	const int SLOT_INCREMENT = 1;
	const int SLOT_DECREMENT = 0;


	srand(RAND_SEED);

	cout << "Welcome to the Plinko simulator!  Enter 3 to see options." << endl << endl;
	do {                   
		cout << "Enter your selection now: ";
		cin >> menuChoice;
		cout << endl;
		if (menuChoice == SINGLE_DROP_CHOICE) {
			cout << "*** Drop a single chip ***" << endl << endl;
			cout << "Which slot do you want to drop the chip in(" << LOWEST_SLOT << " - " << HIGHEST_SLOT << ") ?" << endl;
			cin >> slotChoice;

			if ((slotChoice < LOWEST_SLOT) || (slotChoice > HIGHEST_SLOT)) {     
				cout << "Invalid slot." << endl << endl;
			}
			else {
				cout << fixed;             
				cout << "*** Dropping chip into slot " << slotChoice << " ***" << endl;
				slot = static_cast<double>(slotChoice);
				cout << fixed << setprecision(SLOT_PRECISION) << "Path: [" << slot << ", ";
				for (i = 0; i < NUM_ROWS; ++i) {

					if (slot == LOWEST_SLOT) {     
						slot = slot + SINGLE_SLOT_MOVE;
					}

					else if (slot == HIGHEST_SLOT) {   
						slot = slot - SINGLE_SLOT_MOVE;
					}

					else if ((slot > LOWEST_SLOT) && (slot < HIGHEST_SLOT)) {
						randNum = rand() % 2;             
						if (randNum == SLOT_INCREMENT) {
							slot = slot + SINGLE_SLOT_MOVE;
						}
						else {
							slot = slot - SINGLE_SLOT_MOVE;
						}
					}

					if (i == PATH_OUTPUT_CHECKER) {
						cout << fixed << setprecision(SLOT_PRECISION) << slot << "]" << endl;
					}
					else {
						cout << fixed << setprecision(SLOT_PRECISION) << slot << ", ";
					}
				}
				prizeMoney = ComputeWinnings(slot);
				cout << fixed << setprecision(MONEY_PRECISION) << "Winnings: $" << prizeMoney << endl << endl; 
			}
		}
		if (menuChoice == MULTI_DROP_CHOICE) {
			cout << "*** Drop multiple chips *** " << endl << endl;
			cout << "How many chips do you want to drop (>" << MIN_CHIP_NUM << ")? " << endl << endl;
			cin >> multiDropNum;

			if (multiDropNum <= MIN_CHIP_NUM) {
				cout << "Invalid number of chips.";
			}
			else {
				cout << "Which slot do you want to drop the chip in(" << LOWEST_SLOT << " - " << HIGHEST_SLOT << ") ?" << endl << endl;
				cin >> slotChoice;
				if ((slotChoice < LOWEST_SLOT) || (slotChoice > HIGHEST_SLOT)) {
					cout << "Invalid slot." << endl << endl;
				}
				else {
					for (j = 0; j < multiDropNum; ++j) {
						slot = slotChoice;
						for (i = 0; i < NUM_ROWS; ++i) {

							if (slot == LOWEST_SLOT) {
								slot = slot + SINGLE_SLOT_MOVE;
							}

							else if (slot == HIGHEST_SLOT) {
								slot = slot - SINGLE_SLOT_MOVE;
							}

							else if ((slot > LOWEST_SLOT) && (slot < HIGHEST_SLOT)) {
								randNum = rand() % 2;
								if (randNum == SLOT_INCREMENT) {
									slot = slot + SINGLE_SLOT_MOVE;
								}
								else if (randNum == SLOT_DECREMENT) {
									slot = slot - SINGLE_SLOT_MOVE;
								}
							}

						}

						switch (static_cast<int>(slot)) { 

						case 0:
							prizeMoney = SMALL_PRIZE;
							break;

						case 1:
							prizeMoney = MEDIUM_PRIZE;
							break;

						case 2:
							prizeMoney = LARGE_PRIZE;
							break;

						case 3:
							prizeMoney = NO_PRIZE;
							break;

						case 4:
							prizeMoney = GIANT_PRIZE;
							break;

						case 5:
							prizeMoney = NO_PRIZE;
							break;

						case 6:
							prizeMoney = LARGE_PRIZE;
							break;

						case 7:
							prizeMoney = MEDIUM_PRIZE;
							break;

						case 8:
							prizeMoney = SMALL_PRIZE;
							break;
						}
						totalWinnings = totalWinnings + prizeMoney;     
					}
					cout << "Total winnings on " << multiDropNum << " chips: $" << fixed << setprecision(MONEY_PRECISION)
						<< totalWinnings << endl;
					cout << "Average winnings per chip : $" << totalWinnings / multiDropNum << endl << endl;
				}
				totalWinnings = WINNINGS_RESET;
			}



		}
		if (menuChoice == DISPLAY_MENU_CHOICE) {
			cout << "Menu: Please select one of the following options:" << endl << endl;     
			cout << SINGLE_DROP_CHOICE << " - Drop a single chip into one slot" << endl;
			cout << MULTI_DROP_CHOICE << " - Drop multiple chips into one slot" << endl;
			cout << DISPLAY_MENU_CHOICE << " - Show the options menu" << endl;
			cout << QUIT_PROGRAM_CHOICE << " - Quit the program" << endl;
		}
		if (menuChoice == QUIT_PROGRAM_CHOICE) {
			break;
		}
		if (menuChoice < SINGLE_DROP_CHOICE || menuChoice > QUIT_PROGRAM_CHOICE) {
			cout << "Invalid selection. Enter 3 to see options. " << endl << endl;   
		}

	} while (menuChoice != QUIT_PROGRAM_CHOICE);    

	cout << "Goodbye!";

	return 0;
}
Last edited on
Hello heythere17,

The "ComputeWinnings" function looks good. That is one way I envisioned this function. What I would do different is starting at line 6 I would define any variable that begins with "const". This way you will not be redefining these variables in each function you write. One of the few times global variables are useful because they can not be changed when thay are "const".

On line 142 you call the "ComputeWinnings" function which is good, but at line 185 you retype the switch when you need to call the function. This section is why the function was written.

Next work on taking "drop one chip" and put that into a function. This will be very similar to what you have done. I will have to work on this one to see if there is anything extra needed.

Hope that helps,

Andy
Hello heythere17,

When I started working on your new code I put the menu into a function and changed the beginning of main this way:

1
2
3
4
5
6
7
8
srand(RAND_SEED);

//cout << "Welcome to the Plinko simulator!  Enter 3 to see options." << endl << endl;

do {
	Menu();

	cout << "Enter your selection now: ";


"Menu" is a simple void function that takes no parameters. This works better because when you return to the beginning of the do/while loop the first thing you get is the menu. As you have it the first time the program runs it works. After that the do/while loop only ask the user to enter choice. But what choice? This way the user will know what to enter. And the menu options need to be changed. Option 3 is no longer needed.

About to start the single drop function.

Hope that helps,

Andy
Topic archived. No new replies allowed.