<mosaic.cnfolio.com>
PROGRAM
1. /*
2. START
3. Read 8 inputs, 4 bet locations and 4 bet quantities, each proceeding the other
4. Make sure all data entered is lowercase (irrelevant if input is a number)
5. Check all inputs for validity:
6.    IF bet locations are not within the board limits
7.       THEN print error stating location is not valid
8.    ELSE
9.       IF bet locations are not decimals
10.          THEN print error stating locations cannot be decimals
11.       ELSE
12.          IF bet quantity is less than 0
13.             THEN print error stating that bets cannot be negative
14.          ELSE
15.             Roll 1st bet, if that roll is 37 re-save it as 00
16.             IF the bet input was the letters ODD
17.                THEN
18.                While check variable is less than 17
19.                      IF the rolled number is equal to an odd number (which are saved on a list, whilst the check increments and checks with the next odd value)
20.                         THEN print win and calculate winnings based on odds and leave loop
21.                      IF the rolled value is not on the list of odd numbers
22.                         THEN change a variable to mark a failure
23.             ELSE IF the bet input was the letters EVEN
24.                THEN
25.                While check variable is less than 17
26.                      IF the rolled number is equal to an even number( that are also saved on a list and increment to check with the next value saved)
27.                         THEN print win and calculate winnings based on odds and leave loop
28.                      IF the rolled value is not on the list of even numbers
29.                         THEN change a variable to mark a failure
30.             ELSE IF the bet input was the letters RED
31.                THEN
32.                While check variable is less than 17
33.                      IF the rolled number is equal to a RED number( on a list that is incremented to check with the next value saved)
34.                         THEN print win and calculate winnings based on odds and leave loop
35.                      IF the rolled value is not on the list of red numbers
36.                         THEN change a variable to mark a failure
37.             ELSE IF the bet input was the letters BLACK
38.                THEN
39.                While check variable is less than 17
40.                      IF the rolled number is equal to a BLACK number( on a list that is incremented to check with the next value saved)
41.                         THEN print win and calculate winnings based on odds and leave loop
42.                      IF the rolled value is not on the list of black numbers
43.                         THEN change a variable to mark a failure
44.
45.             ELSE IF the bet input is the same string value as the rolled number
46.                THEN print win and calculate winnings based on odds
47.             ELSE IF the bet input is not the same value as the rolled number
48.                THEN change a variable to mark the failure
49.             IF the variable for failure has been changed
50.                THEN print loss and save the negative of the bet amount
51.
52.      Repeat above process 3 more times to achieve the consecutive rolls but using the 2nd, 3rd and 4th input bet locations and bet amounts
53.
54.   End totals are equal to the results of the 4 bets added together
55.    IF the total is less than 0
56.       THEN replace the word win with lost
58.
59.   Print results using a string for the word win and the value for the bet calculation
60. END
61. */
62.
63. #include <stdio.h>
64. #include <stdlib.h>
65. #include <math.h>
66. #include <time.h>
67. #include <ctype.h>
68. /*extra include statements are required for various parts of my check commands and calculations*/
69.
70. int randomnum(void)
71. {
72.    int randomnumber;
73.    randomnumber = rand() %38;/* seperate function made to return a random value between 0 and 37*/
74.   return(randomnumber);
75. }
76.
77. int main(void)
78. {
79.    time_t t;/* enable the timer, based on the amount of time passed once the code has started */
80.    srand(time(&t));
81.    char inputa[5],inputc[5],inpute[5],inputg[5];
82.    float inputb,inputd,inputf,inputh;
83.    int randomgen1,randomgen2,randomgen3,randomgen4, i=0, failure=0, lower=0;
84.    char roll[2];
85.    char stringcalc[4] = {"Won"};/*set up as a win by default and only changed to loss if a negative result is recorded*/
86.    float calc;
87.    char odd[3];
88.    int odds = 36;
89.    char oddlist[18] = {1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35};
90.    char evenlist[18] = {2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36};
91.    char redlist[18] = {1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36};
92.    char blacklist[18] = {2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35};
93.
94.    printf("Welcome To Roulette, Please Enter Your Four Bets; Location Followed By Bet Amount Consecutively. Red,Black And Odd,Even Bets Are Also Possible\n");
95.
96.    scanf("%s %f %s %f %s %f %s %f", inputa, &inputb, inputc, &inputd, inpute, &inputf, inputg, &inputh);/* the part of the code that actually reads and stores the inputted numbers from the standard input  */
97.
98.    while(lower<4)
99.    {
100.       inputa[lower]=tolower(inputa[lower]);/*this section makes my code non case sensitive when inputing character based bet locations */
101.       lower++;
102.    }
103.    lower=0;
104.     while( lower<4)
105.    {
106.       inputc[lower]=tolower(inputc[lower]);
107.       lower++;
108.    }
109.    lower=0;
110.     while( lower<4)
111.    {
112.       inpute[lower]=tolower(inpute[lower]);
113.       lower++;
114.    }
115.    lower=0;
116.     while( lower<4)
117.    {
118.       inputg[lower]=tolower(inputg[lower]);
119.       lower++;
120.    }
121.
122.      if (atoi(inputa)>36||atoi(inputc)>36||atoi(inpute)>36||atoi(inputg)>36||atoi(inputa)<0||atoi(inputc)<0||atoi(inpute)<0||atoi(inputg)<0)
123.      {
124.      printf("Bet Must Be Made On A Valid Location");/*string converted to integer value to see if the bet placed is actually possible on an american roulette board*/
125.      }
126.      else
127.      {
128.       if (atof(inputa)!=floor(atof(inputa))||atof(inputc)!=floor(atof(inputc))||atof(inpute)!=floor(atof(inpute))||atof(inputg)!=floor(atof(inputg)))
129.       {
130.       printf("Bet Location Cannot Be A Decimal");/*string value converted into a float and then rounded down, if the value is not the same as the original it was a decimal and therefore cant be used*/
131.       }
132.       else
133.       {
134.         if (inputb<1||inputd<1||inputf<1||inputh<1)
135.         {
136.         printf("Bet Quantity Must Be Positive");
137.         }
138.         else
139.         {
140.            randomgen1= randomnum();/*call the above set function and save the results to a variable*/
141.            sprintf(roll,"%d",randomgen1);
142.                if (randomgen1 == 37)
143.               {sprintf(roll,"%s","00");}
144.
145.        if (strcmp(inputa, "odd")== 0)
146.          {
147.           while(i<17)
148.            {
149.            if (atoi(roll) == oddlist[i]) /*check the first value saved on the list if not it will check the next one until its run out of options at which point it will record the failure*/
150.            {
151.              odds = 2;
152.                inputb = inputb*odds;
153.                printf("Congratulations, You Have Won £%.1f On Your First Bet!", inputb);
154.                break;
155.            }
156.            i++;
157.            }
158.            if (i>16)
159.            {
160.            failure = 1;/* change a variable that can be easily checked later to see if the check was unsuccessful*/
161.            }
162.          }
163.       else if (strcmp(inputa, "even")==0)
164.         {
165.          while(i<17)
166.            {
167.            if (atoi(roll) == evenlist[i])/*same as before and which every check in my code */
168.            {
169.              odds = 2;
170.                inputb = inputb*odds;
171.                printf("Congratulations, You Have Won £%.1f On Your First Bet!", inputb);
172.                break;
173.            }
174.             i++;
175.            }
176.            if (i>16)
177.            {
178.            failure = 1;
179.            }
180.
181.         }
182.      else if (strcmp(inputa, "red")== 0)
183.          {
184.           while(i<17)
185.            {
186.            if (atoi(roll) == redlist[i])
187.            {
188.              odds = 2;
189.                inputb = inputb*odds;
190.                printf("Congratulations, You Have Won £%.1f On Your First Bet!", inputb);
191.                break;
192.            }
193.            i++;
194.            }
195.            if (i>16)
196.            {
197.            failure = 1;
198.            }
199.         }
200.      else if (strcmp(inputa, "black")== 0)
201.          {
202.           while(i<17)
203.            {
204.            if (atoi(roll) == blacklist[i])
205.            {
206.              odds = 2;
207.                inputb = inputb*odds;
208.                printf("Congratulations, You Have Won £%.1f On Your First Bet!", inputb);
209.                break;
210.            }
211.            i++;
212.            }
213.            if (i>16)
214.            {
215.            failure = 1;
216.            }
217.          }
218.
219.      else if (strcmp(roll, inputa)==0)
220.      {
221.         odds = 36;
222.           inputb = inputb*odds;
223.               printf("Congratulations, You Have Won £%.1f On Your First Bet!", inputb);
224.      }
225.
226.      else if (strcmp(roll, inputa)!=0)
227.      {
228.       failure=1;
229.      }
230.
231.      if (failure==1)
232.      {
233.        inputb = -inputb;
234.               printf("Unlucky!, You Have Lost £%.1f On Your First Bet, The Number Rolled Was %s, Whilst You Bet On %s", -inputb, roll, inputa);
235.      }
236.
237.        i=0;
238.        failure = 0;
239.          randomgen2= randomnum();
240.            sprintf(roll,"%d",randomgen2);
241.                if (randomgen2 == 37)
242.               {sprintf(roll,"%s","00");}
243.
244.        if (strcmp(inputc, "odd")== 0)
245.          {
246.           while(i<17)
247.            {
248.            if (atoi(roll) == oddlist[i])
249.            {
250.              odds = 2;
251.                inputd = inputd*odds;
252.                printf("\nCongratulations, You Have Won £%.1f On Your Second Bet!", inputd);
253.                break;
254.
255.            }
256.            i++;
257.            }
258.            if (i>16)
259.            {
260.            failure = 1;
261.            }
262.          }
263.       else if (strcmp(inputc, "even")==0)
264.         {
265.          while(i<17)
266.            {
267.            if (atoi(roll) == evenlist[i])
268.            {
269.              odds = 2;
270.                inputd = inputd*odds;
271.                printf("\nCongratulations, You Have Won £%.1f On Your Second Bet!", inputd);
272.                break;
273.            }
274.             i++;
275.            }
276.            if (i>16)
277.            {
278.            failure = 1;
279.            }
280.
281.         }
282.      else if (strcmp(inputc, "red")== 0)
283.          {
284.           while(i<17)
285.            {
286.            if (atoi(roll) == redlist[i])
287.            {
288.              odds = 2;
289.                inputd = inputd*odds;
290.                printf("\nCongratulations, You Have Won £%.1f On Your Second Bet!", inputd);
291.                break;
292.            }
293.            i++;
294.            }
295.            if (i>16)
296.            {
297.            failure = 1;
298.            }
299.         }
300.      else if (strcmp(inputc, "black")== 0)
301.          {
302.           while(i<17)
303.            {
304.            if (atoi(roll) == blacklist[i])
305.            {
306.              odds = 2;
307.                inputd = inputd*odds;
308.                printf("\nCongratulations, You Have Won £%.1f On Your Second Bet!", inputd);
309.                break;
310.            }
311.            i++;
312.            }
313.            if (i>16)
314.            {
315.            failure = 1;
316.            }
317.          }
318.      else if (strcmp(roll, inputc)==0)
319.      {
320.         odds = 36;
321.           inputd = inputd*odds;
322.               printf("\nCongratulations, You Have Won £%.1f On Your Second Bet!", inputd);
323.      }
324.
325.      else if (strcmp(roll, inputc)!=0)
326.      {
327.       failure=1;/*if the bet placed is just a normal number but not equal to the roll again a failure will be recorded*/
328.      }
329.
330.      if (failure==1)
331.      {
332.        inputd = -inputd;
333.               printf("\nUnlucky!, You Have Lost £%.1f On Your Second Bet, The Number Rolled Was %s, Whilst You Bet On %s", -inputd, roll, inputc);
334.      }
335.         i=0;/* reset the ckecking variable for even/odd/red/black*/
336.         failure = 0;
337.             randomgen3= randomnum();
338.            sprintf(roll,"%d",randomgen3);
339.                if (randomgen3 == 37)
340.               {sprintf(roll,"%s","00");}
341.
342.        if (strcmp(inpute, "odd")== 0)
343.          {
344.           while(i<17)
345.            {
346.            if (atoi(roll) == oddlist[i])
347.            {
348.              odds = 2;
349.                inputf = inputf*odds;
350.                printf("\nCongratulations, You Have Won £%.1f On Your Third Bet!", inputf);
351.                break;
352.
353.            }
354.            i++;
355.            }
356.            if (i>16)
357.            {
358.            failure = 1;
359.            }
360.          }
361.       else if (strcmp(inpute, "even")==0)
362.         {
363.          while(i<17)
364.            {
365.            if (atoi(roll) == evenlist[i])
366.            {
367.              odds = 2;
368.                inputf = inputf*odds;
369.                printf("\nCongratulations, You Have Won £%.1f On Your Third Bet!", inputf);
370.                break;
371.            }
372.             i++;
373.            }
374.            if (i>16)
375.            {
376.            failure = 1;
377.            }
378.
379.         }
380.      else if (strcmp(inpute, "red")== 0)
381.          {
382.           while(i<17)
383.            {
384.            if (atoi(roll) == redlist[i])
385.            {
386.              odds = 2;
387.                inputf = inputf*odds;
388.                printf("\nCongratulations, You Have Won £%.1f On Your Third Bet!", inputf);
389.                break;
390.            }
391.            i++;
392.            }
393.            if (i>16)
394.            {
395.            failure = 1;
396.            }
397.         }
398.      else if (strcmp(inputa, "black")== 0)
399.          {
400.           while(i<17)
401.            {
402.            if (atoi(roll) == blacklist[i])
403.            {
404.              odds = 2;
405.                inputf = inputf*odds;
406.                printf("\nCongratulations, You Have Won £%.1f On Your Third Bet!", inputf);
407.                break;
408.            }
409.            i++;
410.            }
411.            if (i>16)
412.            {
413.            failure = 1;
414.            }
415.          }
416.      else if (strcmp(roll, inpute)==0)
417.      {
418.         odds = 36;
419.           inputf = inputf*odds;
420.               printf("\nCongratulations, You Have Won £%.1f On Your Third Bet!", inputf);
421.      }
422.
423.      else if (strcmp(roll, inpute)!=0)
424.      {
425.       failure=1;
426.      }
427.
428.      if (failure==1)
429.      {
430.        inputf = -inputf;
431.               printf("\nUnlucky!, You Have Lost £%.1f On Your Third Bet, The Number Rolled Was %s, Whilst You Bet On %s", -inputf, roll, inpute);
432.      }
433.
434.
435.         i=0;
436.         failure = 0;
437.             randomgen4= randomnum();
438.            sprintf(roll,"%d",randomgen4);
439.                if (randomgen4 == 37)
440.               {sprintf(roll,"%s","00");}
441.
442.        if (strcmp(inputg, "odd")== 0)
443.          {
444.           while(i<17)
445.            {
446.            if (atoi(roll) == oddlist[i])
447.            {
448.              odds = 2;
449.                inputh = inputh*odds;
450.                printf("\nCongratulations, You Have Won £%.1f On Your Fourth Bet!", inputh);
451.                break;
452.
453.            }
454.            i++;
455.            }
456.            if (i>16)
457.            {
458.            failure = 1;
459.            }
460.          }
461.       else if (strcmp(inputg, "even")==0)
462.         {
463.          while(i<17)
464.            {
465.            if (atoi(roll) == evenlist[i])
466.            {
467.              odds = 2;
468.                inputh = inputh*odds;
469.                printf("\nCongratulations, You Have Won £%.1f On Your Fourth Bet!", inputh);
470.                break;
471.            }
472.             i++;
473.            }
474.            if (i>16)
475.            {
476.            failure = 1;
477.            }
478.
479.         }
480.      else if (strcmp(inputg, "red")== 0)
481.          {
482.           while(i<17)
483.            {
484.            if (atoi(roll) == redlist[i])
485.            {
486.              odds = 2;
487.                inputh = inputh*odds;
488.                printf("\nCongratulations, You Have Won £%.1f On Your Fourth Bet!", inputh);
489.                break;
490.            }
491.            i++;
492.            }
493.            if (i>16)
494.            {
495.            failure = 1;
496.            }
497.         }
498.      else if (strcmp(inputg, "black")== 0)
499.          {
500.           while(i<17)
501.            {
502.            if (atoi(roll) == blacklist[i])
503.            {
504.              odds = 2;
505.                inputh = inputh*odds;
506.                printf("\nCongratulations, You Have Won £%.1f On Your Fourth Bet!", inputh);
507.                break;
508.            }
509.            i++;
510.            }
511.            if (i>16)
512.            {
513.            failure = 1;
514.            }
515.          }
516.      else if (strcmp(roll, inputg)==0)
517.      {
518.         odds = 36;
519.           inputh = inputh*odds;
520.               printf("\nCongratulations, You Have Won £%.1f On Your Fourth Bet!", inputh);
521.      }
522.
523.      else if (strcmp(roll, inputg)!=0)
524.      {
525.       failure=1;
526.      }
527.
528.      if (failure==1)
529.      {
530.        inputh = -inputh;
531.               printf("\nUnlucky!, You Have Lost £%.1f On Your Fourth Bet, The Number Rolled Was %s, Whilst You Bet On %s", -inputh, roll, inputg);
532.      }
533.
534.      }
535.      }
536.      }
537.
538.
539.      calc = inputb+inputd+inputf+inputh;/* net profit/loss is the sum of all the winnings/losses */
540.
541.    if (calc<0)
542.    {
543.       strcpy(stringcalc, "Lost");/* nice way of making a printf statement always grammatically correct, given a certain situation change the whole word when printed as a string*/
544.       calc = -calc;
545.    }
546.
547.    printf("\nIn Total You %s £%.1f", stringcalc, calc);/*final print showing net gain or loss*/
548.
549.
550.    }