-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroulette.c
More file actions
executable file
·320 lines (270 loc) · 8.36 KB
/
roulette.c
File metadata and controls
executable file
·320 lines (270 loc) · 8.36 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
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
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "bet.h"
#define BETS_SIZE 100
float doBets(bet**, int, int, float);
int dobet(bet**, int, int, float);
int rrange(int, int);
int main()
{
srand(time(NULL));
bet* bets[BETS_SIZE];
int betcount = 0;
int hit = 0;
float money = 350.0;
printf("Welcome to the Casa de la Muerto Casino!\n");
printf("Right now, we're playing 3 Dice Roulette.\n");
printf("To learn how to play, go to http://en.wikipedia.org/wiki/Roulette\n");
printf("====================================================\n");
printf("You start with $%.2f.\n", money);
do
{
int select = 0;
int stop = 0;
do
{
fflush(stdout);
fflush(stdin);
printf("====================================================\n");
printf("You can:\n");
printf("1. Place a bet on a single number (pays 5:1 + bet).\n");
printf("2. Place a bet on row 3, 6, 9, 12, 15 or 18 (pays 3:1 + bet).\n");
printf("3. Place a bet on odd (pays 1:1 + bet).\n");
printf("4. Place a bet on even (pays 1:1 + bet).\n");
printf("5. Place a bet on 1 to 9 (pays 2:1 + bet).\n");
printf("6. Place a bet on 10 to 18 (pays 2:1 + bet).\n");
printf("7. Throw the dice.\n");
printf("8. Walk away from the table.\n");
printf("Please select what you would like to do (enter a number from 1 - 8): ");
int temp = scanf("%i", &select);
if(temp == EOF)
{
printf("Please enter a number.\n");
}
else if(select < 1 || select > 8)
{
printf("Please enter a valid number between one and eight.\n");
}
else
{
printf("\n\n");
switch(select)
{
case 1: betcount = dobet(bets, betcount, BET_SINGLE, money); break;
case 2: betcount = dobet(bets, betcount, BET_ROWS, money); break;
case 3: betcount = dobet(bets, betcount, BET_ODD, money); break;
case 4: betcount = dobet(bets, betcount, BET_EVEN, money); break;
case 5: betcount = dobet(bets, betcount, BET_1TO9, money); break;
case 6: betcount = dobet(bets, betcount, BET_10TO18, money); break;
case 7: printf("No more bets!\n"); stop = 1; break;
case 8: printf("You leave with $%.2f.\n", money);
if(money > 350.0) printf("You won $%.2f.\n", money - 350);
else if(money < 350.0) printf("You lost $%.2f.\n", 350 - money);
else printf("You made no money on what you orginally had.\n");
return 0;
}
fflush(stdout);
fflush(stdin);
}
}
while(stop == 0);
printf("\n\n");
printf("Throwing the dice...\n");
hit = rrange(0, 18);
printf("The dice came up %i.\n", hit);
money = doBets(bets, betcount, hit, money);
betcount = 0;
}
while(1);
}
float doBets(bet** bets, int betcount, int hit, float money)
{
char* temp = (char*)malloc(15);
for(int i = 0; i < betcount; i++)
{
bet* b = bets[i];
temp = betType(b, temp);
printf("You placed a %s bet:\n", temp);
if(didPayoff(b, hit) == 1)
{
float won = getPayoff(b, hit);
money += won;
printf("You won $%.2f!\n", won);
}
else
{
money -= b->amount;
printf("You lost $%.2f!\n", b->amount);
}
printf("You now have $%.2f.\n", money);
}
free(temp);
fflush(stdout);
fflush(stdin);
return money;
}
int dobet(bet** bets, int betcount, int type, float money)
{
bet* bet1 = (bet*)malloc(sizeof(bet));
if(type == BET_SINGLE)
{
int whichOne = 0;
do
{
fflush(stdout);
fflush(stdin);
printf("What number do you want to place your bet on (0 - 18)? ");
int temp = scanf("%i", &whichOne);
if(temp == EOF)
{
printf("Please enter a number.\n");
}
else if(temp < 0 || temp > 18)
{
printf("Please enter a valid number between zero and eighteen.\n");
}
else
{
float amount = 0.0;
do
{
fflush(stdout);
fflush(stdin);
printf("How much do you want to bet? ");
int temp = scanf("%f", &amount);
if(temp == EOF)
{
printf("Please enter a number.\n");
}
else if(temp < 0.0)
{
printf("You can't bet less than nothing!\n");
}
else if(temp > money)
{
printf("You can't bet more money than you have!\n");
}
else
{
bet1->type = whichOne;
bet1->amount = amount;
break;
}
}
while(1);
break;
}
}
while(1);
}
else if(type == BET_ROWS)
{
int whichOne = 0;
do
{
fflush(stdout);
fflush(stdin);
printf("Which row do you want to place your bet on (3, 6, 9, 12, 15, 18)? ");
int temp = scanf("%i", &whichOne);
if(temp == EOF)
{
printf("Please enter a number.\n");
}
else if(whichOne != 3 && whichOne != 6 && whichOne != 9 && whichOne != 12
&& whichOne != 15 && whichOne != 18)
{
printf("Please enter a valid number: 3, 6, 9, 12, 15, or 18.\n");
}
else
{
float amount = 0.0;
do
{
fflush(stdout);
fflush(stdin);
printf("How much do you want to bet? ");
int temp = scanf("%f", &amount);
if(temp == EOF)
{
printf("Please enter a number.\n");
}
else if(temp < 0.0)
{
printf("You can't bet less than nothing!\n");
}
else if(temp > money)
{
printf("You can't bet more money than you have!\n");
}
else
{
switch(whichOne)
{
case 3: bet1->type = BET_ROW3; break;
case 6: bet1->type = BET_ROW6; break;
case 9: bet1->type = BET_ROW9; break;
case 12: bet1->type = BET_ROW12; break;
case 15: bet1->type = BET_ROW15; break;
case 18: bet1->type = BET_ROW18; break;
}
bet1->amount = amount;
break;
}
}
while(1);
break;
}
}
while(1);
}
else if(type == BET_ODD || type == BET_EVEN || type == BET_1TO9 || type == BET_10TO18)
{
int whichOne = 0;
float amount = 0.0;
do
{
fflush(stdout);
fflush(stdin);
printf("How much do you want to bet? ");
int temp = scanf("%f", &amount);
if(temp == EOF)
{
printf("Please enter a number.\n");
}
else if(temp < 0.0)
{
printf("You can't bet less than nothing!\n");
}
else if(temp > money)
{
printf("You can't bet more money than you have!\n");
}
else
{
bet1->type = type;
bet1->amount = amount;
break;
}
}
while(1);
}
if(betcount > BETS_SIZE)
{
printf("Sorry, too many bets made.\n");
return -1;
}
fflush(stdout);
fflush(stdin);
bets[betcount++] = bet1;
return betcount;
}
int rrange(int a, int b)
{
int temp = rand();
while(temp < a || temp > b)
{
temp = rand();
}
return temp;
}