<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. START
  3. SCAN for either 2 integers or 8 integers
  4. IF
  5.    Just 2 integers are found
  6.    THEN
  7.       Enter the RED/BLACK game mode
  8.    ELSE IF
  9.       8 integers are found
  10.       THEN
  11.          Enter the standard roulette game mode
  12. END IF
  13. ***RED/BLACK game mode***
  14. Randomly generate a number between 1 and 2
  15. Check if user input matches randomly generated number
  16. IF
  17.    Number matches
  18.    THEN
  19.       Display winnings
  20.    ELSE IF
  21.       Number does not match
  22.    THEN
  23.       Display losses
  24. END IF
  25. Display error messages for incorrect inputs
  26.  
  27. ***Standard Roulette game mode***
  28. Randomly generate a number between 0-36
  29. Randomly generate a number between 0-36
  30. Randomly generate a number between 0-36
  31. Randomly generate a number between 0-36
  32. Check if 1st bet matched 1st spin
  33. IF
  34.    Bet number matches
  35.    THEN
  36.       Display winnings
  37.    ELSE
  38.       Bet number does not match
  39.       THEN
  40.          Display losses
  41. END IF
  42. Check if 2nd bet matched 2nd spin
  43. IF
  44.    Bet number matches
  45.    THEN
  46.       Display winnings
  47.    ELSE
  48.       Bet number does not match
  49.       THEN
  50.          Display losses
  51. END IF
  52. Check if 3rd bet matched 3rd spin
  53. IF
  54.    Bet number matches
  55.    THEN
  56.       Display winnings
  57.    ELSE
  58.       Bet number does not match
  59.       THEN
  60.          Display losses
  61. END IF
  62. Check if 4th bet matched 4th spin
  63. IF
  64.    Bet number matches
  65.    THEN
  66.       Display winnings
  67.    ELSE
  68.       Bet number does not match
  69.       THEN
  70.          Display losses
  71. END IF
  72. Display net profits/losses
  73. Display error messages for incorrect inputs
  74. */
  75.  
  76. #include <stdio.h>
  77. #include <stdlib.h>
  78. #include <time.h>
  79.  
  80. /*Initialising variables*/
  81. int num_of_match_input = 0;
  82. int num1;
  83. int num2;
  84. int num3;
  85. int num4;
  86. int bet1;
  87. int bet2;
  88. int bet3;
  89. int bet4;
  90. int numR1;
  91. int numR2;
  92. int numR3;
  93. int numR4;
  94. double res1;
  95. double res2;
  96. double res3;
  97. double res4;
  98. double net;
  99.  
  100. /*Start of the program*/
  101. int main( void )
  102. {
  103.  
  104.     num_of_match_input = scanf("%d %d %d %d %d %d %d %d", &num1, &bet1, &num2, &bet2, &num3, &bet3, &num4, &bet4);
  105.  
  106.  
  107.     if (num_of_match_input == 2)  /*Only two inputs are entered*/
  108.     {
  109.  
  110.         if(num1 != 1 && num1 != 2)  /*Checking that just either 1 or 2 has been entered*/
  111.             printf("Please only either enter 1 for BLACK or 2 for RED \n");
  112.  
  113.         else
  114.         {
  115.             srand(time(0));         /*Generating random number*/
  116.  
  117.             numR1 = rand() % 2;    /*Random number between 0-1*/
  118.             numR1++;      /*Manually add one to bring the range from 1-2*/
  119.  
  120.             if (numR1 == 1)
  121.                 printf("The result is BLACK \n");
  122.  
  123.             else if (numR1 == 2)
  124.                 printf("The result is RED \n");
  125.  
  126.             if (numR1 == num1)
  127.             {
  128.                 res1 = (bet1 * 2);
  129.                 printf("Congratulations you have won %.2lf \n", res1);
  130.             }
  131.             else
  132.                 printf("Please try again, you have lost %d \n", bet1);
  133.  
  134.         }
  135.     }
  136.  
  137.     else if (num_of_match_input == 8)  /*8 inputs are entered*/
  138.     {
  139.         if(num1 < 0 || num2 < 0 || num3 < 0 || num4 < 0) /*Checking for negative betting numbers*/
  140.             printf("Please only enter positive integers for betting on \n");
  141.         else
  142.         {
  143.             srand(time(0));      /*Generating random number*/
  144.  
  145.             numR1 = rand() % 37/*Spin number 1*/
  146.             numR2 = rand() % 37/*Spin number 2*/
  147.             numR3 = rand() % 37/*Spin number 3*/
  148.             numR4 = rand() % 37/*Spin number 4*/
  149.  
  150.          /*Assigning RED, BLACK or ZERO to each possible random number outcome*/
  151.             if(numR1 == 2||numR1 == 4||numR1 ==6||numR1 ==8||numR1 ==10||numR1 ==11||numR1 ==13||numR1 ==15||numR1 ==17||numR1 ==20||numR1 ==22||numR1 ==24||numR1 ==26||numR1 ==28||numR1 ==29||numR1 ==31||numR1 ==33||numR1 ==35)
  152.                 printf("The first number is %d Black \n", numR1);
  153.             else if(numR1 == 1||numR1 ==3||numR1 ==5||numR1 ==7||numR1 ==9||numR1 ==12||numR1 ==14||numR1 ==16||numR1 ==18||numR1 ==19||numR1 ==21||numR1 ==23||numR1 ==25||numR1 ==27||numR1 ==30||numR1 ==32||numR1 ==34||numR1 ==36)
  154.                 printf("The first number is %d Red \n", numR1);
  155.             else if(numR1 == 0)
  156.                 printf("The first number is %d \n", numR1);
  157.             else
  158.                 printf("Invalid roulette number entered, please enter a number 0-36");
  159.             if(numR2 == 2||numR2 ==4||numR2 ==6||numR2 ==8||numR2 ==10||numR2 ==11||numR2 ==13||numR2 ==15||numR2 ==17||numR2 ==20||numR2 ==22||numR2 ==24||numR2 ==26||numR2 ==28||numR2 ==29||numR2 ==31||numR2 ==33||numR2 ==35)
  160.                 printf("The second number is %d Black \n", numR2);
  161.             else if(numR2 == 1||numR2 ==3||numR2 ==5||numR2 ==7||numR2 ==9||numR2 ==12||numR2 ==14||numR2 ==16||numR2 ==18||numR2 ==19||numR2 ==21||numR2 ==23||numR2 ==25||numR2 ==27||numR2 ==30||numR2 ==32||numR2 ==34||numR2 ==36)
  162.                 printf("The second number is %d Red \n", numR2);
  163.             else if(numR2 == 0)
  164.                 printf("The second number is %d \n", numR2);
  165.             else
  166.                 printf("Invalid roulette number entered, please enter a number 0-36");
  167.             if(numR3 == 2||numR3 ==4||numR3 ==6||numR3 ==8||numR3 ==10||numR3 ==11||numR3 ==13||numR3 ==15||numR3 ==17||numR3 ==20||numR3 ==22||numR3 ==24||numR3 ==26||numR3 ==28||numR3 ==29||numR3 ==31||numR3 ==33||numR3 ==35)
  168.                 printf("The third number is %d Black \n", numR3);
  169.             else if(numR3 == 1||numR3 ==3||numR3 ==5||numR3 ==7||numR3 ==9||numR3 ==12||numR3 ==14||numR3 ==16||numR3 ==18||numR3 ==19||numR3 ==21||numR3 ==23||numR3 ==25||numR3 ==27||numR3 ==30||numR3 ==32||numR3 ==34||numR3 ==36)
  170.                 printf("The third number is %d Red \n", numR3);
  171.             else if(numR3 == 0)
  172.                 printf("The third number is %d \n", numR3);
  173.             else
  174.                 printf("Invalid roulette number entered, please enter a number 0-36");
  175.             if(numR4 == 2||numR4 ==4||numR4 ==6||numR4 ==8||numR4 ==10||numR4 ==11||numR4 ==13||numR4 ==15||numR4 ==17||numR4 ==20||numR4 ==22||numR4 ==24||numR4 ==26||numR4 ==28||numR4 ==29||numR4 ==31||numR4 ==33||numR4 ==35)
  176.                 printf("The fourth number is %d Black \n", numR4);
  177.             else if(numR4 == 1||numR4 ==3||numR4 ==5||numR4 ==7||numR4 ==9||numR4 ==12||numR4 ==14||numR4 ==16||numR4 ==18||numR4 ==19||numR4 ==21||numR4 ==23||numR4 ==25||numR4 ==27||numR4 ==30||numR4 ==32||numR4 ==34||numR4 ==36)
  178.                 printf("The fourth number is %d Red \n", numR4);
  179.             else if(numR4 == 0)
  180.                 printf("The fourth number is %d \n", numR4);
  181.             else
  182.                 printf("Invalid roulette number entered, please enter a number 0-36");
  183.  
  184.  
  185.             if(num1 == numR1)   /*Checking 1st bet against 1st spin*/
  186.             {
  187.                 res1 = (bet1*36);
  188.                 printf("Congratulations you have won %.2lf \n", res1);
  189.             }
  190.             else
  191.                 printf("Please try again, you lost %d \n", bet1);
  192.  
  193.             if(num2 == numR2)   /*Checking 2nd bet against 2nd spin*/
  194.             {
  195.                 res2 = (bet2*36);
  196.                 printf("Congratulations you have won %.2lf \n", res2);
  197.             }
  198.             else
  199.                 printf("Please try again, you lost %d \n", bet2);
  200.  
  201.             if(num3 == numR3)   /*Checking 3rd bet against 3rd spin*/
  202.             {
  203.                 res3 = (bet3*36);
  204.                 printf("Congratulations you have won %.2lf \n", res3);
  205.             }
  206.             else
  207.                 printf("Please try again, you lost %d \n", bet3);
  208.  
  209.             if(num4 == numR4)   /*Checking 4th bet against 4th spin*/
  210.             {
  211.                 res4 = (bet4*36);
  212.                 printf("Congratulations you have won %.2lf \n", res4);
  213.             }
  214.             else
  215.                 printf("Please try again, you lost %d \n", bet4);
  216.  
  217.             net = (0 - bet1 - bet2 - bet3 - bet4 + res1 + res2 + res3 + res4);   /*Calculating net profits/losses*/
  218.  
  219.             printf("Your net profits for these four spins are %.2lf \n", net);
  220.         }
  221.     }
  222.     else
  223.         printf("Please either enter 2 integers for RED/BLACK game or 8 integers for general Roulette game spins. \n")/*Error message if user has not input 2 numbers or 8 numbers*/
  224. }