-
Notifications
You must be signed in to change notification settings - Fork 0
/
LottoAssignment.c
257 lines (207 loc) · 5.01 KB
/
LottoAssignment.c
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
/*Assignment 2 : Lottery game.
Student no: C11720431
Date: 11/03/2012
*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define SIZE 6
void fullentry(int *e, int *b);
void displayentry(int *displaye, int *displayb);
void sortedentry(int *array, int *extra);
void results(int *numarray, int *numextra);
int main(void)
{
char optionchoice = ' ';;
int entry[SIZE];
int bonus;
//fullentry(entry, &bonus);
while(optionchoice != '#')
{
printf ("Menu:\n"
"\n1. Enter players chosen numbers"
"\n2. Display players chosen numbers"
"\n3. Sort players numbers in ascending order"
"\n4. Check if player is a winner"
"\n5. Display the frequency of the numbers entered\n");
scanf("%1s",&optionchoice);
getchar();
switch(optionchoice)
{
case '1':
{
fullentry(entry, &bonus);
break;
}
case '2':
{
displayentry(entry, &bonus);
break;
}
case '3':
{
sortedentry(entry, &bonus);
break;
}
case '4':
{
results(entry, &bonus);
break;
}
case '5':
{
break;
}
case '#':
{
break;
}
default:
{
printf("\nError: Invalid choice, please try again\n");
break;
}
}
system("pause");
}
}
void fullentry(int *e, int *b)
{
int i = 0;
printf( "Please enter your 6 numbers between 1 and 42:\n");
while (i<SIZE)
{
scanf("%2d/n", (e+i));
flushall();
if ((*(e+i) > 42 || *(e+i) < 1) || (*(e+i) == '\o'))
{
printf( "Invalid entry\n");
printf( "Please enter a number between 1 and 42:\n");
i--;
}
else
{
i++;
}
/*else
{
int j;
for(j=0; j<SIZE; j++)
{
if(*(e+j) == *(e+i))
{
*(e+j) = *(e+j++);
i--;
}
++j;
}
}*/
}
printf("Please enter your bonus number:\n");
int k;
scanf("%2d", b);
while (*b > 42 || *b < 1)
{
printf("Invalid number please try again:\n");
scanf("%2d", b);
}
for(k=0; k<SIZE; k++)
{
while (*b == *(e+k))
{
printf("Invalid choice. Please enter your bonus number\n");
scanf("%2d", b);
}
}
printf("Your entry has been processed\n");
}
void displayentry(int *displaye, int *displayb)
{
int i;
printf("Your chosen numbers are:");
for(i=0; i<SIZE; i++)
{
printf("%d ", *(displaye+i));
}
printf("- %d\n", *displayb);
}
void sortedentry(int *array, int *extra)
{
int i, j, min, temp;
for(i=0; i<*(array-1); i++)
{
min = i;
for(j = i+1; j<SIZE; j++)
{
if (*(array+j) < *(array+min))
{
min = j;
}
}
temp = *(array+min);
*(array+min) = *(array+i);
*(array+i) = temp;
}
for(i=0; i<SIZE; i++)
{
printf("%d ", *(array+i));
}
printf("- %d\n", *extra);
}
void results(int *numarray, int *numextra)
{
int i;
int match = 0;
int entrybonus = 0;
int win[SIZE] = { 1, 3, 5, 7, 9, 11 };
int winbonus = 42;
for(i=0; i<SIZE; i++)
{
if (*(numarray+i) == *(win+i))
{
match++;
}
if (*numextra == winbonus)
{
entrybonus = 1;
}
}
switch(match)
{
case 3:
if(entrybonus == 1)
{
printf("Free lotto scratch card\n");
}
else
{
printf("Not a winner\n");
}
break;
case 4:
if(entrybonus == 1)
{
printf("Night out\n");
}
else
{
printf("Full petrol tank\n");
}
break;
case 5:
if(entrybonus == 1)
{
printf("Almost - just 1 away\n");
}
else
{
printf("Holidays paid for\n");
}
break;
case 6:
printf("Jackpot\n");
break;
default:
printf("Not a winner\n");
}
}