<mosaic.cnfolio.com>
PROGRAM
1. #include <stdio.h>
2. #include <stdlib.h>
3. #include <time.h>
4.
5. int main (void)
6.
7. {
8. /*
9. American Roulette Pseudo Code:
10. START
11.       PRINT welcome message
12.
13.       Set number of bets to 0
14.
15.       WHILE the number of bets is less than 4
16.
17.       GET bet value and money amount
18.
19.       IF bet value is between 0-36 and a positive integer
20.
21.       IF money amount is above 0
22.
23.       Spin wheel to get a number between 0-36 and the additional 00 value
24.       Display winning number
25.       Display bet value
26.       Display money amount
27.
28.       IF bet value equals winning number
29.       THEN
30.       Display bet value multiplied by 35 as payout
31.       Display subtotal balance - payout amount added to money amount
32.       ELSE
33.       Display 0 as payout
34.       Make the balance a minus money amount
35.
36.       END IF
37.
38.       Display subtotal balance
39.       Add subtotal balance onto total balance
40.       Increase number of bets by 1
41.
42.       ELSE display error message
43.       END IF
44.
45.       ELSE display error message
46.       END IF
47.
48.       END WHILE
49.
50.       Display total balance which is the sum of the individaul balance of each bet
51.
52. END
53. */
54.
55. int money;
56. int payout;
57. int tbalance;
58. int balance;
59. int number;
60. int bet;
61. int i;
62.
63.
64. i=0; /*Set number of bets to zero*/
65. tbalance=0; /*Set total balance to zero*/
66.
67. printf("Welcome to American Roulette \n\n");/*Welcome message*/
68.
69. /*Instructions for game*/
70. printf("Straight-up bet: Choose a single number. High risk, good luck! 35 to 1\n\n");
71. printf("Enter your four bets and the corresponding money amount in pairs \n\n");
72.
73. for(i=0;i<4;i++)/*For loop used to repeat for 4 bets*/
74. {
75.
76. bet=-1; /*Set bet to -1 so unless an input is read error message appears*/
77. money=-1;/*Set money to -1 so unless an input is read error message appears*/
78.
79. scanf("%d %d", &bet,&money);
80.
81. if((bet<37)&&(bet>0))
82. {
83. if(money>0)
84. {
85. /*Random number generator*/
86.   srand( time( 0 ) );
87.
88.   number = rand() %38; /* Random number generator for numbers 0-37 */
89.
90.   printf("Winning number:");
91.
92.   if(number>36)
93.   {
94.   switch(number)
95.   {case  37 : printf("00 \n");break;} /* In the case of a 37 the value "00" will be displayed */
96.   }
97.
98.  else
99.  {printf("%d \n", number );} /*Print result of random number generator */
100.
101.  printf("Bet: %d \n",bet);
102.  printf("Money amount: £%d \n",money);
103.
104.  if (number==bet)/*Checks to see if winning number is equal to bet*/
105.  {
106.  payout = money*35; /*Calculates the payout value of straight bet which is 35 to 1*/
107.  printf("Winner!\n");
108.  printf("Payout: £%d \n", payout);
109.  balance = money+payout;/*Calculates the subtotal balance of the individual bet*/
110.
111.  }
112.  else
113.  {
114.  payout=0;/*Makes payout equal to 0*/
115.  printf("You lost better luck next time\n");
116.  printf("Payout: £%d \n", payout);
117.  balance=-money;/*Makes subtotal balance equal to minus the money amount*/
118.  }
119.
120.  printf("Balance: £%d \n\n", balance);
121.
122.  tbalance += balance;/*Adds subtotal balance on to the final total balance*/
123.
124.  }
125.
126.  /*ERROR Messages*/
127.  else
128.  {
129.  printf("ERROR money betted must be a positive integer (whole number)\n");
130.  printf("ERROR one or more of your bets are invalid or missing, \n");
131.  printf("Enter your four bets and the corresponding money amount in pairs")
132.  return 0;
133.  }
134.
135.  }
136.
137.  else
138.  {
139.  printf("ERROR bet number must be between 0-36 \n");
140.  printf("ERROR one or more of your bets are invalid or missing, \n");
141.  printf("Enter your four bets and the corresponding money amount in pairs")
142.  return 0;
143.  }
144.
145.  }
146.
147.  printf("Total Balance: £%d ",tbalance);
148.
149.  }