-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgambling_project.cpp
More file actions
197 lines (85 loc) · 2.48 KB
/
Copy pathgambling_project.cpp
File metadata and controls
197 lines (85 loc) · 2.48 KB
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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void five_balls(int[], int);
void selection_sort(int[], int);
void duplicate_check(int[], int);
void swap(int &, int &);
void show_picks(int[], int, int);
unsigned seed = time(0);
int main()
{
const int RED_BALLS = 26;
int games;
srand(seed);
do
{
cout << "How many games would you like to play (max 24 games)? ";
cin >> games;
} while (games > 25);
const int BALLS = 5;
int lucky_numbers[BALLS];
int six_ball;
for (int play = 1; play <= games; play++)
{
five_balls(lucky_numbers, BALLS);
selection_sort(lucky_numbers, BALLS);
duplicate_check(lucky_numbers, BALLS);
six_ball = rand() % (RED_BALLS - 1 + 1) + 1;
show_picks(lucky_numbers, BALLS, six_ball);
}
}
void five_balls(int num_list[], int size)
{
const int WHITE_BALLS = 69, WHITE_PICKS = 5;
for (int index = 0; index < WHITE_PICKS; index++)
num_list[index] = rand() % (WHITE_BALLS - 1 + 1) + 1;
}
void selection_sort(int num_list[], int size)
{
int min_index, min_value;
for (int start = 0; start < (size - 1); start++)
{
min_index = start;
min_value = num_list[start];
for (int index = start + 1; index < size; index++)
{
if (num_list[index] < min_value)
{
min_value = num_list[index];
min_index = index;
}
}
swap(num_list[min_index], num_list[start]);
}
}
void swap(int &a, int &b)
{
int temp = a;
a = b;
b = temp;
}
void duplicate_check(int num_list[], int size)
{
int count = 0;
const int WHITE_BALLS = 69;
while (count < (size - 2))
{
if (num_list[count] == num_list[count + 1])
{
num_list[count + 1] = rand() % (WHITE_BALLS - 1 + 1) + 1;
selection_sort(num_list, size);
count = 0;
}
else
count++;
}
}
void show_picks(int num_list[], int size, int six_num)
{
cout << "\nWhite Balls are: ";
for (int index = 0; index < 5; index++)
cout << num_list[index] << " ";
cout << "Power Ball is: " << six_num << endl;
}