<mosaic.cnfolio.com>
PROGRAM
1. /*  Roulette Program */
2. /*
3. START
4.       Implement simulation of the roulette game using the American style
5.      Bet number include 0~36 and 00
6.      Odd is 1 to 35
7.       SET the times to one
8.        WHILE times is less than 5
9.            WHILE bet number is less than 0 and bet number is more than 37
10.              THEN
11.                Input bet number
12.             IF bet number is "00"
13.                THEN
14.                   Bet number equals 37
15.             END IF
16.             ELSE
17.                 THEN
18.                   Display input bet number equals the same of integer
19.                  IF bet number is less than 0 and bet number is more than 36
20.                     THEN
21.                       Display input error, input agian
22.             END ELSE
23.           END WHILE
24.         WHILE bet money amount is not a positive whole number
25.               THEN
26.                Input bet money amount
27.             IF bet money amount is not a positive whole number
28.                    THEN
29.                    Display input error, input again
30.             END IF
31.           END WHILE
32.        END WHILE
33.        See simulate winning roulette numbers
34.        IF winning roulette number is 37
35.         THEN
36.           Display winning roulette number is "00"
37.        END IF
38.       ELSE
39.         THEN
40.           Display winning roulette number
41.        END ELSE
42.       WHILE timer is less than 5
43.          IF winning roulette number equals bet number
44.           THEN
45.             Display winning money amount
46.           END IF
47.         ELSE
48.             THEN
49.               Display lossing money amount
50.         END ELSE
51.       END WHILE
52.       Display total payment money amount
53.       Display total lossing monry amount
54.       Display total winning money amount
55.       Display total money amount
56. END
57. */
58.
59. #include <stdio.h>
60. #include <string.h>
61. #include <stdlib.h>
62. #include <time.h>
63.
64. int main(void)                 /* Main program */
65.
66. {
67.     char number = {0};      /* Define input bet number character strings */
68.    char *doublezero = "00";    /* Define doublezero character strings */
69.    int bet_number = {0};    /* Initialise real bet number variable */
70.    int bet_money = {0};     /* Initialise bet money amount variable */
71.    int winning_number = {0};   /* Initialise winning number variable */
72.    int winning = {0};       /* Initialise winning money amount variable */
73.    int lossing = {0};       /* Initialise lossing money amount variable */
74.
76.     printf("Welcome playing implement simulation of the roulette game.\n");
77.    printf("Implement simulation of the roulette game using the American style");
78.    printf("Input each bet number is 0~36 and 00.\n");
79.    printf("Input ecah money amount is positive whole number, and odds is 1:35.\n");
80.
81.    /* Initialise i is 1
82.       While i is less than 5 */
83.    for(int i=1; i<5; ++i)
84.    {
85.       /* While real bet number is less than 0 and more than 37 */
86.       do
87.       {
88.          /* Player choose each bets number and get it */
89.          printf("Input the bet[%d] number:\n",i);
90.          scanf("%s", &number);
91.          /* If input bet number is "00" */
92.          if (strncmp(number, doublezero, 2) == 0)
93.          {
94.             /* Real bet number equal 37 */
95.             bet_number[i] = 37;
96.             printf("Input the bet[%d] number is %s.\n", i, doublezero);
97.          }
98.          /* Else input bet number is not "00" */
99.          else
100.          {
101.             /* Input character strings equal integer variable string */
102.             bet_number[i] = atoi(number)
103.             printf("Input bet[%d] number is %d.\n", i, bet_number[i]);
104.             /* Display the input error */
105.             if(bet_number[i] < 0 || bet_number[i] > 36)
106.             {
107.                /* Display input error */
108.                printf("Input error,please input the bet[%d] number again:\n", i);
109.             }
110.          }
111.       }
112.       while(bet_number[i] < 0 || bet_number[i] > 37);
113.
114.       /* While bet money amount is less than 0 */
115.       do
116.       {
117.          /* Input each bet money amount */
118.          printf("Input the money amountthe of bet[%d]:\n",i);
119.          scanf("%d", &bet_money[i]);
120.          printf("the money amount the of bet[%d] is %d.\n", i, bet_money[i]);
121.          /* Display input error */
122.          if (bet_money[i]<0)
123.          {
124.             printf("input error,please input out again:\n");
125.          }
126.       }
127.       while(bet_money[i]<0);
128.    }
129.
130.     /* Initialise the random number generation with the current time
131.      This only needs to be called once */
132.    srand(time(NULL));
133.    /* The rand() function is called each time a new random number is required.
134.      The modulus operator generates a number between 0 and 37 */
135.     winning_number=rand()%37;
136.
137.    /*If winning number is 37 to display "00" */
138.    if(winning_number==37)
139.    {
140.       printf("winner number is %s.\n", doublezero);
141.    }
142.    /* Else winning number is not 37 to display winning number */
143.    else
144.    {
145.       printf("winner number is %d.\n", winning_number);
146.    }
147.
148.    /* Initialise i is 1
149.       While i is less than 5 */
150.    for(int i=1; i<5;  ++i)
151.    {
152.       /* If winning number is the same as real bet number */
153.       if(winning_number==bet_number)
154.        {
155.          /* Display each bet winning money */
156.          printf("winner\n");
157.          winning[i]=(bet_money[i]*35);
158.          printf("winning money of bet[%d] is %d.\n", i, winning[i]);
159.       }
160.       /* Else winning number is different winning number */
161.       else
162.       {
163.          /* Display each bet lossing money */
164.          printf("losser\n");
165.          lossing[i]=bet_money[i];
166.          printf("lossing money of bet[%d] is %d.\n", i, lossing[i]);
167.       }
168.    }
169.
170.    /* Display the final result */
171.    printf("paying total money is %d.\n", bet_money+bet_money+bet_money+bet_money);
172.    printf("winning total money is %d.\n", winning+winning+winning+winning);
173.    printf("lossing total money is %d.\n", lossing+lossing+lossing+lossing);
174.    printf("total money is %d.\n", winning+winning+winning+winning-lossing-lossing-lossing-lossing);
175.
176.    return 0;
177. }