Sorting Lowest to Highest for Powerball

I don't know how I would do this, I'm suppose to make the first five white balls from the user and what the computer outputs from lowest to highest, so that the program can tell the user that he or she won this amount of money with the matches. How would I go about doing that? Below is what I have.

Thanks in advance!


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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>
#include <conio.h>
#include <ctime>
#include "Powerball.h"
#include <array>
#include <algorithm>
#include <functional>

using namespace std;

char username;

const short LOTTO_SIZE = 6;	 // Size of arrays for tracking picks

// Output shown when the player wins
const char* const winTxt[] = { 
"Winner! Jackpot! - $23,000,000",
"Winner! Five white balls - $1,000,000",
"Winner! Four white balls & powerball - $10,000!",
"Winner! Four white balls - $100!",
"Winner! Three white balls & powerball - $100!",
"Winner! Three white balls - $7!",
"Winner! Two white balls & powerball - $7!",
"Winner! One white ball & powerball - $4!",
"Winner! Powerball only - $4!"};

void header()
{
	cout << "Sean Kilbane C++ II\n"
		 << "Powerball: Program 1\n\n";
	cout << "You will be asked to pick a total of six numbers.\n"
		 << "The first five numbers must be a value between 1-55.\n"
		 << "The last number, the powerball, must be\n"
		 << "between 1-42, and may repeat a previously picked value.\n"
		 << "All picks must be whole number values.\n\n"
		 << "=============================================================\n"
		 << "There are nine possible winning combinations:\n"
		 << "Five matches + powerball  $23,000,000  Odds 1 in 175,223,510\n"
		 << "Five matches              $1,000,000   Odds 1 in 153,632.65\n"
		 << "Four matches + powerball  $10,000      Odds 1 in 648,975.96\n"
		 << "Four matches              $100         Odds 1 in 19,078.53\n"
		 << "Three matches + powerball $100         Odds 1 in 12,244.83\n"
		 << "Three matches             $7           Odds 1 in 360.14\n"
		 << "Two matches + powerball   $7           Odds 1 in 706.43\n"
		 << "One match + powerball     $4           Odds 1 in 110.81\n"
		 << "Powerball only            $4           Odds 1 in 55.41\n"
		 << "=============================================================\n\n";
}

struct pbSet
{
	float alone;
	float match1;
	float match2;
	float match3;
	float match4;
	float match5;
};

// Used to keep tally of wins if playing until jackpot
struct winCount
{
	pbSet powerball;
	float match3;
	float match4;
	float match5;
} winnings = {0, 0, 0, 0, 0, 0};	// Counter to track the winnings

int menu()
{
	short temp = 0;
	string username;
	cout << "Enter your name: ";
	cin >> username;
	cout << endl
		<< "1. Play\n";
	cout << username + ", pick an menu option: ";
	cin >> temp;
	cout << endl;
	if (!cin)
	{
		cin.clear();
		cin.ignore();
	}
	else
		return temp;
}

void game(const bool& type)
{
	short *playerPicks,	 // numbers chosen by the player
	*randPicks;	 // random numbers (winning picks)
	float counter = 1.0f;	 // counter of number of tries
	bool win = false;	 // tracks win condition
	playerPicks = makePicks(LOTTO_SIZE);
	cout << endl
		<< "You've chosen: ";
	for (short i = 0; i < LOTTO_SIZE; i++)
		cout << playerPicks[i] << " ";
	_getch();
	{
		while (!win)
		{
			randPicks = makePicksRand(LOTTO_SIZE);
			cout << "\nTry " << counter << ": ";
			for (short i = 0; i < LOTTO_SIZE; i++)
				cout << randPicks[i] << " ";
			cout << endl;
			win = checkWin(playerPicks, randPicks, type);
			counter++;
			delete[] randPicks;
		}
	}
}

short* makePicks(const short& size)
{
	short *temp = new short[size];
	bool repeat = false;
	cout << "Pick your first five numbers.\n" 
		 << "Choices must be from 1-55, and may not repeat\n";
	for (short i = 0; i < LOTTO_SIZE;)
	{
		if ((i == 5) && (!repeat))
		{
			cout << "Now, pick your powerball number.\n" 
				<< "Choice must be from 1-42, and may\n"
				<< "repeat any previous pick.\n";
			repeat = true;
		}
		cout << "Pick " << (i + 1) << ": ";
		cin >> temp[i];
		if (!cin)
		{
			cin.clear();
			cin.ignore();
			cout << "Invalid input.\n";
		}
		else
		{
			if (validate(i, temp))
				i++;
			else
				cout << "Pick " << (i + 1) << " conflicts with a previous \n"
					 << "choice or is invalid.\n";
		}
	}
	return temp;
}

short* makePicksRand(const short& size)
{
	short *temp = new short[size];
	for (short i = 0; i < LOTTO_SIZE;)	
	{
		if (i == 5)
			temp[i] = (rand() % 42) + 1;
		else
			temp[i] = (rand() % 55) + 1;
		if (validate(i, temp))
			i++;
	}
	return temp;
}



bool validate(const short& num, const short* picks)
{
	if (num == 5)	// when checking the last number (powerball)
	{
		if ((picks[num] < 1) || (picks[num] > 42))
			return false;
		else
			return true;
	}
	else	 // checks all other numbers
	{
		if ((picks[num] > 55) || (picks[num] < 1))
			return false;
		else if (num > 0)
		for (short i = 0; i <= num; i++)
		if (picks[i] == picks[i + 1])
			return false;
		return true;
	}
}

bool checkWin(const short* player, const short* random, const bool& type)
{
	bool pbMatch = false;
	short matches = 0;
	for (short i = 0; i < LOTTO_SIZE; i++)
	{
		if (player[i] == random[i])
		{
			if (i == 5)
				pbMatch = true;
			else
				matches++;
		}
	}
	if (pbMatch)
		switch (matches)
	{
		case 0:	 // $4
			cout << winTxt[8] << endl;
			if (type)
			{
				winnings.powerball.alone++;
				return false;
			}
			else
				return true;
			break;
		case 1:	 // $4
			cout << winTxt[7] << endl;
			if (type)
			{
				winnings.powerball.match1++;
				return false;
			}
			else
				return true;
			break;
		case 2:	 // $7
			cout << winTxt[6] << endl;
			if (type)
			{
				winnings.powerball.match2++;
				return false;
			}
			else
				return true;
			break;
		case 3:	 // $100
			cout << winTxt[4] << endl;
			if (type)
			{
				winnings.powerball.match3++;
				return false;
			}
			else
				return true;
			break;
		case 4:	 // $100,000
			cout << winTxt[2] << endl;
			if (type)
			{
				winnings.powerball.match4++;
				return false;
			}
			else
				return true;
			break;
		case 5:	 // jackpot
			cout << winTxt[0] << endl;
			return true;
	}
	else
		switch (matches)
	{
		case 3:	 // $7
			cout << winTxt[5] << endl;
			if (type)
			{
				winnings.match3++;
				return false;
			}
			else
				return true;
			break;
		case 4:	 // $100
			cout << winTxt[3] << endl;
			if (type)
			{
				winnings.match4++;
				return false;
			}
			else
				return true;
			break;
		case 5:	 // $1,000,000
			cout << winTxt[1] << endl;
			if (type)
			{
				winnings.match5++;
				return false;
			}
			else
				return true;
			break;
	}
	return false;
}
Anyone?
What problems do you have with your program?
It doesn't check the results right, it will run till it sees that the powerball is hit and that's it. It should be able to check every input and say in any order, then till you won this much.
Still need help.
Hello? Anyone out there?
Topic archived. No new replies allowed.