<mosaic.cnfolio.com>
PROGRAM
1. /*
2. START
3. SET all balances to 0
4. SET bet counter to 0
5. SET error check values to -11
6. SCAN to obtain 8 input values, bet value and bet amount
7. SRAND and RAND () to generate random values to simulate roulette
8. PRINT spin result x4 times
9.
10. IF error check values equals -11
11.    THEN
12.       PRINT error occured
13.       terminate program
14. IF bets is less than 0 and is greater than 37
15.    THEN
16.       PRINT error occured
17.       terminate program
18.
19. WHILE bet counter is less than 4
20. PRINT bet number and bet amount
21. IF spin equal bet value
22.    THEN
23.       ADD bet amount to balance
24.       PRINT balance
25. ELSE
26.    SUBSTRACT betmoney from balance
27.    PRINT bet amount and balance
28. END IF
29. ADD 1 to the bet counter
30. END WHILE
31.
32. PRINT total balance
33. END
34.
35. NOTES:
36. IF 0 > bet > 37
37. Test values - 0 bets, negative bets, not enough bet too many bets
38. negative values, no values, lack of bets, letters and signs
39. ERROR CHECKS
40. */
41. #include <stdio.h>
42. #include <stdlib.h>
43. #include <time.h>
44.
45. int main ( void )
46. {
47. int spin1, spin2, spin3, spin4;
48. int betmoney1 = -11, betmoney2 = - 11, betmoney3 = - 11, betmoney4 = -11;
49. int bet1 = -11, bet2 = -11, bet3 = -11, bet4 = -11; /* error check */
50. int balance1 = 0, balance2 = 0, balance3 = 0, balance4 = 0; /* makes sure the balance is at same value */
51. int extravalue = -11; /* this will be for error checking for any extra values inputted */
52. printf("Please input 8 values first the number to bet on and then how much to bet, repeat this 4 times\n"); /* explains to user how to input the values */
53.
54. srand( time ( 0 ) );
55. spin1 = rand () % 37; /* generates random number between 0-37, the numbers 37 will represent 00 */
56. spin2 = rand () % 37; /* each spin will be for a different player */
57. spin3 = rand () % 37;
58. spin4 = rand () % 37;
59.
60. scanf("%d %d %d %d %d %d %d %d %s", &bet1, &betmoney1, &bet2, &betmoney2, &bet3, &betmoney3, &bet4, &betmoney4, &extravalue); /* scans assigns variables */
61.
62. if(extravalue != -11) /* if any extra values terminate */
63.    {
64.    printf("You inputted too many values.");
65.    exit(0);
66.    }
67.
68. if (0 <= bet1 && 0 <= bet2 && 0 <= bet3 && 0 <= bet4 )  /* error checking to see if bet number is valid  */
69. {
70.    if (37 >= bet1 && 37 >= bet2 && 37 >= bet3 && 37 >= bet4)
71.    {
72.       printf("Valid bets\n");
73.    }
74.    else
75.    {
76.       printf("There was an error with the inputs, please check the betnumbers are between 0-37\n");
77.       exit(0);
78.    }
79. }
80. else
81. {
82.    printf("There was an error with the inputs, please check the betnumbers are between 0-37\n");
83.    exit(0);
84. }
85.
86. if (betmoney1 == -11 || betmoney2 == -11 || betmoney3 == -11 || betmoney4 == -11)
87. {
88.    printf("There was an error with the money inputs, please finish input enough values.");
89.    exit(0);
90. }
91.
92.
93. if (bet1 < 0 || bet2 < 0 || bet3 < 0 || bet4 < 0 )
94. {
95.    printf("There was an error with the inputs, please check the betnumbers are between 0-37\n");
96.    exit(0);
97. }
98. if (bet1 > 38 || bet2 > 38 || bet3 > 38 || bet4 > 38)
99. {
100.    printf("There was an error with the inputs, please check the betnumbers are between 0-37\n");
101.    exit(0);
102. }
103.
104. if (bet1 == -11 || bet2 == -11 || bet3 == -11 || bet4 == -11) /* error checking to see if user has inputted values */
105. {
106.    printf("There was an error with the bet numbers inputs, you need to add \n");
107.    exit(0);
108. }
109.
110.
111. else if (bet1 != -11 && bet2 != -11 && bet3 != -11 && bet4 != -11)
112. {
113.    printf("The first spin result was %d\n", spin1); /*shows the spin result to the user */
114.    printf("The second spin result was %d\n", spin2);
115.    printf("The third spin result was %d\n", spin3);
116.    printf("The fourth spin result was %d\n", spin4);
117.    printf("Player1 you bet on the number %d using \$%d\n", bet1, betmoney1); /* shows bet number and bet amount to user */
118.
119. if (spin1 == bet1) /* each paragraph represents a different player */
120. {
121.    balance1 = balance1 + betmoney1 * 36;
122.    printf("You won \$%d, your balance is now \$%d \n", betmoney1 * 36, balance1); /* Win is * 36 because you win *35 the amount you bet plus you get your bet amount back */
123. }
124. else if (spin1 != bet1)
125. {
126.    balance1 = balance1 - betmoney1;
127.    printf("You lost \$%d, your balance is now \$%d \n", betmoney1, balance1);
128. }
129.
130.    printf("Player2 you bet on the number %d using \$%d\n", bet2, betmoney2)
131. if (spin2 == bet2)
132. {
133.    balance2 = balance2 + betmoney2 * 36;
134.    printf("You won \$%d, your balance is now \$%d \n", betmoney2 * 36, balance2 + betmoney2);
135. }
136. else if (spin2 != bet2)
137. {
138.    balance2 = balance2 - betmoney2;
139.    printf("You lost \$%d, your balance is now \$%d \n", betmoney2, balance2);
140. }
141.
142.    printf("Player3 you bet on the number %d using \$%d\n", bet3, betmoney3);
143. if (spin3 == bet3)
144. {
145.    balance3 = balance3 + betmoney3 * 36;
146.    printf("You won \$%d, your balance is now \$%d \n", betmoney3 * 36, balance3 + betmoney3);
147. }
148. else if (spin3 != bet3)
149. {
150.    balance3 = balance3 - betmoney3;
151.    printf("You lost \$%d, your balance is now \$%d \n", betmoney3, balance3);
152. }
153.
154.    printf("Player4 you bet on the number %d using \$%d\n", bet4, betmoney4);
155. if (spin4 == bet4)
156. {
157.    balance4 = balance4 + betmoney4 * 36;
158.    printf("You won \$%d, your balance is now \$%d \n", betmoney4 * 36, balance4 + betmoney4);
159. }
160. else if (spin4 != bet4)
161. {
162.    balance4 = balance4 - betmoney4;
163.    printf("You lost \$%d, your balance is now \$%d \n", betmoney4, balance4);
164. }
165.
166. printf("Overall the balance for the players are \$%d, \$%d, \$%d, \$%d totalling up to \$%d\n", balance1, balance2, balance3, balance4, balance1 + balance2 + balance3 + balance4);
167. }
168. }
169.
170.
171.
172. /* NOTES
173. looopss
174. while ( counter
175.
176. american roulette 1/38
177. obtain 8 input bets (4 players*2 bet numbers)
178. generate random number for winning numbers
179. display user bet number, user bet amount,winning number, payout value
180. display the total loss/profit for each player
181.
182.
183. END*/