Need help adding score to this slot machine

I need help showing the user their points when they press 'n' to stop playing the slot machine, but it always displays "0" as the score. Any pointers?

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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#include <fstream>


using namespace std;

enum Options { TOMATO, ORANGE, APPLE, PINEAPPLE, STRAWBERRY, GRAPES };

const int MILIDELAY = 1; //defines the delay in miliseconds as a constant
const int NUMSPINS = 50; //defines the number of time to spin the slot machine as a constant

char menu();
char choice;
int point;

string outputOptions(Options x); //Returns the string equivalent of the enum type Options value
void spinning();
void getPos(Options& x); //This function cycles through the Options values
void delay(); //delays the output by the number of miliseconds as defined by the constant MILIDELAY
void spinMachine(Options& one, Options& two, Options& three); //Simulates the spinning of the slot machine for a specifed number of spins as defined by NUMSPINS
void getStopOrder(int& first, int& second, int& last);
int getScore(Options pos1, Options pos2, Options pos3);

void game2Text();
void game3Text();
void game1(); // Choice 1 
void game2(); // Choice 2
void game3(); // Choice 3
void menuScore(); // Choice 4

int main()
{
	char menuChoice = 'z';

	while (menuChoice != 'f')
	{
		menuChoice = menu();
		switch (menuChoice)
		{
		case '1':
			game1(); // menu choice game 1
			break;
		case '2':
			game2(); // menu choice game 2
			break;
		case '3':
			game3(); // menu choice game 3
			break;
		case '4':
			menuScore(); // menu for checking score
			break;
		default:
			cout << "Thank you for playing. ";
		}
	} // End while

	return 0;
}

char menu()
{
	char choice;

	cout << " -----Welcome to the main menu-----\n";
	cout << " Press 1 for game 1\n";
	cout << " press 2 for game 2\n";
	cout << " press 3 for game 3\n";
	cout << " press 4 for Score menu\n";
	cout << " press F to exit program\n";
	cin >> choice;
	cout << endl;

	return choice;
}

void game1()
{
	spinning();
	string outputOptions(Options& x);
	void getPos(Options& x);
	delay();
	void spinMachine(Options& posOne, Options& posTwo, Options& posThree);
	void getStopOrder(int& first, int& second, int& last);
	int getScore(Options posOne, Options posTwo, Options posThree);
}

void game2()
{
	game2Text();
}

void game3()
{
	game3Text();
}

void menuScore()
{

}

void game2Text()
{
	cout << "**INSERT SECOND GAME CODE HERE**" << endl;
	char userChoice = 'z';

	while (userChoice != 'n')
	{
		cout << "\nWould you like to play again? (y/n): ";
		cin >> userChoice;
		cout << endl;
	}
}

void game3Text()
{
	cout << "**INSERT THIRD GAME CODE HERE**" << endl;
	char userChoice = 'z';

	while (userChoice != 'n')
	{
		cout << "\nWould you like to play again? (y/n): ";
		cin >> userChoice;
		cout << endl;
	}
}

void spinning()
 {
		//defines three spinning position each starting with a different value
		Options posOne = TOMATO;
		Options posTwo = APPLE;
		Options posThree = GRAPES;
		char userChoice = 'z';

		while (userChoice != 'n')
		{
			spinMachine(posOne, posTwo, posThree); //spins the slotmachines positions
			cout << "\nWould you like to spin again? (y/n): ";
			cin >> userChoice;
			if (userChoice == 'n')
			{
				cout << "\nYou have a score of: " << point << "." << endl;
			}
		}
		
	}

	string outputOptions(Options x)
	{
		//Returns the string equivalent of the enum type Options value
		switch (x)
		{
		case TOMATO:
			return "TOMATO";
			break;
		case ORANGE:
			return "ORANGE";
			break;
		case APPLE:
			return "APPLE";
			break;
		case PINEAPPLE:
			return "PINEAPPLE";
			break;
		case STRAWBERRY:
			return "STRAWBERRY";
			break;
		case GRAPES:
			return "GRAPES";
			break;

		}
		return 0;
	}

	void getPos(Options& x)
	{
		//This function cycles through the Options values
		//each time it is called it increments to the next Options value and
		//starts from the beginning of the list when it reaches the end of the list
		if (x == GRAPES)
			x = TOMATO;
		else
			x = static_cast<Options>(x + 1);

	}
	void delay()
	{
		//delays the output by the number of miliseconds passed
		clock_t endWait = clock() + MILIDELAY;
		while (clock() < endWait) {} //do nothing

	}
	void spinMachine(Options& posOne, Options& posTwo, Options& posThree)
	{
		int first, second, last;
		int count = 0;

		//determines how many spins to stop the first and second position to stop before the last.
		//numStopFirst must be greater than numStopSecond 
		int numStopFirst = 20, numStopSecond = 10;

		while (count <= NUMSPINS)
		{
			//randomly determine which position to stop first, second, and last
			getStopOrder(first, second, last);
			//determines how long to spin each position based on their stop order
			if (first == 1)
			{
				if (count <= NUMSPINS - numStopFirst)
				{
					getPos(posOne);
				}
				if (second == 2)
				{
					if (count <= NUMSPINS - numStopSecond)
						getPos(posTwo);
					getPos(posThree);
				}
				else
				{
					if (count <= NUMSPINS - numStopSecond)
						getPos(posThree);
					getPos(posTwo);
				}
			}
			else if (first == 2)
			{
				if (count <= NUMSPINS - numStopFirst)
				{
					getPos(posTwo);
				}
				if (second == 3)
				{
					if (count <= NUMSPINS - numStopSecond)
						getPos(posThree);
					getPos(posOne);
				}
				else
				{
					if (count <= NUMSPINS - numStopSecond)
						getPos(posOne);
					getPos(posThree);
				}
			}
			else
			{
				if (count <= NUMSPINS - numStopFirst)
				{
					getPos(posThree);
				}
				if (second == 2)
				{
					if (count <= NUMSPINS - numStopSecond)
						getPos(posTwo);
					getPos(posOne);
				}
				else
				{
					if (count <= NUMSPINS - numStopSecond)
						getPos(posOne);
					getPos(posTwo);
				}
			}

			//increments the value of Options each time the loop is execute
			//getPos(posOne);
			//getPos(posTwo);
			//getPos(posThree);
			delay(); //delay the execution of the cout statement by the number of miliseconds as defined by the constant MILIDELAY 
			//displays the value of each position on the same line in the conole
			cout << "Spinning:  " << setw(15) << outputOptions(posOne) << setw(15) << outputOptions(posTwo) << setw(15) << outputOptions(posThree) << "\r";
			count++; //increments count so that the loop can terminate
		}
	}

	void getStopOrder(int& first, int& second, int& last)
	{
		//randomly determines the order in which to stop spinning each position

		srand(time(0));
		first = rand() % 3 + 1;
		last = rand() % 3 + 1;
		if (first == last)
		{
			if (last == 3)
			{
				last = 1;
				second = 2;
			}
			else
			{
				last = last + 1;
				if (last == 3)
					second = 1;
				else
					second = last + 1;
			}
		}
		else if (first == 1)
		{
			if (last == 2)
				second = 3;
			else
				second = 2;
		}
		else if (first == 2)
		{
			if (last == 3)
				second = 1;
			else
				second = 2;
		}
		else
		{
			if (last == 1)
				second = 2;
			else
				second = 1;
		}
	}

	int getScore(Options posOne, Options posTwo, Options posThree)
	{
		if (posOne == posTwo || posTwo == posThree)
		{
			point = (point+10);
		}
		else if (posOne == posTwo || posOne == posThree || posTwo == posThree)
		{
			point = (point+3);
		}

		return point;
	}
Last edited on
Line 83, 85-87: These are function declarations, not function calls. They're not going to get called.


Topic archived. No new replies allowed.