<mosaic.cnfolio.com>
PROGRAM
  1. /*START
  2.    SET the data types for the variables that will be used
  3.    READ the eight input values and set them as either a table number or a bet number
  4.    for each spin DISPLAY the table number and the bet amount
  5.    
  6.    SET the limits of what table numbers are allowed so that it fits for playing roulette
  7.    and bet numbers so that at least 1p or more must have been bet for it to be valid otherwise
  8.    OUTPUT error messages. Example,
  9.       IF (bet is less than or equal to 0)
  10.          THEN
  11.             OUTPUT(Bet invalid. Enter correct values)
  12.          END
  13.    Create the random number generation to produce the numbers for 4 roulette spins.
  14.       Have number 37 assigned to output 00 so that it fits american roulette
  15.    DISPLAY the winning number for each spin
  16.    DISPLAY wether any of the bets have won and the total winnings for the bet and then calculate the
  17.    total winnings for all for bets and output the value. Example,
  18.       IF(randmom numbers dont equal and table numbers)
  19.          THEN
  20.             DISPLAY(No bets won. Total winnings=)
  21.          END
  22. END*/
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <time.h>
  27.  
  28. int main(void)
  29. {
  30.    int number, number1, number2, number3;
  31.    int table[4];
  32.    float bet[4];
  33.  
  34.       /*READ the input values
  35.         SET them to either table[] or bet[]*/
  36.       scanf("%d %f %d %f %d %f %d %f", &table[0], &bet[0], &table[1], &bet[1], &table[2], &bet[2],
  37.       &table[3], &bet[3]);
  38.      
  39.       /*ASSIGN the inputs to spin and money values and OUTPUT them*/
  40.       printf("Spin 1: Number=%d Money bet=%.2f\n", table[0], bet[0]);
  41.       printf("Spin 2: Number=%d Money bet=%.2f\n", table[1], bet[1]);
  42.       printf("Spin 3: Number=%d Money bet=%.2f\n", table[2], bet[2]);
  43.       printf("Spin 4: Number=%d Money bet=%.2f\n\n", table[3], bet[3]);
  44.  
  45.       /*SET the parameters for bet[] and table[]
  46.         OUTPUT error messages if inputs don't fit in the parameters*/
  47.    if(bet[0]<=0)
  48.       {
  49.       printf("Bet 1 invalid. Please enter correct money value\n");
  50.       }
  51.    if((table[0]>=38)||(table[0]<0))
  52.       {
  53.       printf("Bet 1 invalid. Please enter correct table value\n");
  54.       }
  55.    if(bet[1]<=0)
  56.       {
  57.       printf("Bet 2 invalid. Please enter correct money value\n");
  58.       } 
  59.    if((table[1]>=38)||(table[1]<0))
  60.       {
  61.       printf("Bet 2 invalid. Please enter correct table value\n");
  62.       }
  63.    if(bet[2]<=0)
  64.       {
  65.       printf("Bet 3 invalid. Please enter correct money value\n");
  66.       } 
  67.    if((table[2]>=38)||(table[2]<0))  
  68.       {
  69.       printf("Bet 3 invalid. Please enter correct table value\n");
  70.       }
  71.    if(bet[3]<=0)
  72.       {
  73.       printf("Bet 4 invalid. Please enter correct money value\n");
  74.       } 
  75.    if((table[3]>=38)||(table[3]<0))
  76.       {
  77.       printf("Bet 4 invalid. Please enter correct table value\n");
  78.       }
  79.       
  80.       /*Initlialise the random number generation with the current time
  81.         ONLY needs to be called once*/
  82.       srand(time(0));
  83.      
  84.       /*The rand() function is called each time a new random number is required
  85.         The modulus operator generates a number between 0 and 37
  86.         Random numbers are generated four times to replicate four spins
  87.         IF 37 is generated then 00 is OUTPUTTED*/
  88.       number=rand()%38;
  89.    if(number==37)
  90.       {   
  91.       printf("\nSpin 1 winning number=00\n");
  92.       }
  93.    else
  94.       {
  95.       printf("\nSpin 1 winning number=%d\n", number);
  96.       }
  97.       number1=rand()%38;
  98.    if(number1==37)
  99.       {   
  100.       printf("Spin 2 winning number=00\n");
  101.       }
  102.    else
  103.       {
  104.       printf("Spin 2 winning number=%d\n", number1);
  105.       }
  106.       number2=rand()%38;
  107.    if(number2==37)
  108.       {   
  109.       printf("Spin 3 winning number=00\n");
  110.       }
  111.    else
  112.       {
  113.       printf("Spin 3 winning number=%d\n", number2);
  114.       }
  115.       number3=rand()%38;
  116.    if(number3==37)
  117.       {   
  118.       printf("Spin 4 winning number=00\n\n");
  119.       }
  120.    else
  121.       {
  122.       printf("Spin 4 winning number=%d\n\n", number3);
  123.       }
  124.       
  125.       /*IF statements for all possible outcomes of the four spins
  126.         ALLOWS for the calculation of the total winnigns after each bet and after all four spins*/
  127.    if((number!=table[0])&&(number1!=table[1])&&(number2!=table[2])&&(number3!=table[3]))
  128.       {
  129.       printf("No bets won. Total loss=%.2f\n", bet[0]+bet[1]+bet[2]+bet[3]);
  130.       }
  131.    if((number==table[0])&&(number1==table[1])&&(number2==table[2])&&(number3==table[3]))
  132.       {
  133.       printf("All bets won!\nBet one winnings=%.2f\nBet two winnings=%.2f\nBet three winnings=%.2f\nBet four winnings=%.2f\nTotal winnings=%.2f\n",
  134.       bet[0]*2, bet[1]*2, bet[2]*2, bet[3]*2, ((bet[0]*2)+(bet[1]*2)+(bet[2]*2)+(bet[3]*2)));
  135.       }
  136.  
  137.    if((number==table[0])&&(number1!=table[1])&&(number2!=table[2])&&(number3!=table[3]))
  138.       {
  139.       printf("Bet one won. Winnings=%.2f\nTotal winnings=%.2f\n",
  140.       bet[0]*2, (bet[0]*2)-bet[1]-bet[2]-bet[3]);
  141.       }
  142.    if((number!=table[0])&&(number1==table[1])&&(number2!=table[2])&&(number3!=table[3]))
  143.       {
  144.       printf("Bet two won. Winnings=%.2f\nTotal winnings=%.2f\n",
  145.       bet[1]*2, (bet[1]*2)-bet[0]-bet[2]-bet[3]);
  146.       }
  147.    if((number!=table[0])&&(number1!=table[1])&&(number2==table[2])&&(number3!=table[3]))
  148.       {
  149.       printf("Bet three won. Winnings=%.2f\nTotal winnings=%.2f\n",
  150.       bet[2]*2, (bet[2]*2)-bet[0]-bet[1]-bet[3]);
  151.       }
  152.    if((number!=table[0])&&(number1!=table[1])&&(number2!=table[2])&&(number3==table[3]))
  153.       {
  154.       printf("Bet four won. Winnings=%.2f\nTotal winnings=%.2f\n",
  155.       bet[3]*2, (bet[3]*2)-bet[0]-bet[1]-bet[2]);
  156.       }
  157.    
  158.    if((number==table[0])&&(number1==table[1])&&(number2!=table[2])&&(number3!=table[3]))
  159.       {
  160.       printf("Bet one won. Winnings=%.2f\nBet two won. Winnings=%.2f\nTotal winnings=%.2f\n",
  161.       bet[0]*2, bet[1]*2, ((bet[0]*2)+(bet[1]*2))-bet[2]-bet[3]);
  162.       }
  163.    if((number==table[0])&&(number1!=table[1])&&(number2==table[2])&&(number3!=table[3]))
  164.       {
  165.       printf("Bet one won. Winnings=%.2f\nBet three won. Winnings=%.2f\nTotal winnings=%.2f\n",
  166.       bet[0]*2, bet[2]*2, ((bet[0]*2)+(bet[2]*2))-bet[1]-bet[3]);
  167.       }
  168.    if((number==table[0])&&(number1!=table[1])&&(number2!=table[2])&&(number3==table[3]))
  169.       {
  170.       printf("Bet one won. Winnings=%.2f\nBet four won. Winnings=%.2f\nTotal winnings=%.2f\n",
  171.       bet[0]*2, bet[3]*2, ((bet[0]*2)+(bet[3]*2))-bet[1]-bet[2]);
  172.       }
  173.    
  174.    if((number!=table[0])&&(number1==table[1])&&(number2==table[2])&&(number3!=table[3]))
  175.       {
  176.       printf("Bet two won. Winnings=%.2f\nBet three won. Winnings=%.2f\nTotal winnings=%.2f\n",
  177.       bet[1]*2, bet[2]*2, ((bet[1]*2)+(bet[2]*2))-bet[0]-bet[3]);
  178.       }
  179.    if((number!=table[0])&&(number1==table[1])&&(number2!=table[2])&&(number3==table[3]))
  180.       {
  181.       printf("Bet two won. Winnings=%.2f\nBet four won. Winnings=%.2f\nTotal winnings=%.2f\n",
  182.       bet[1]*2, bet[3]*2, ((bet[1]*2)+(bet[3]*2))-bet[0]-bet[2]);
  183.       }
  184.    
  185.    if((number!=table[0])&&(number1!=table[1])&&(number2==table[2])&&(number3==table[3]))
  186.       {
  187.       printf("Bet three won. Winnings=%.2f\nBet four won. Winnings=%.2f\nTotal winnings=%.2f\n",
  188.       bet[2]*2, bet[3]*2, ((bet[2]*2)+(bet[3]*2))-bet[0]-bet[1]);
  189.       }
  190.    
  191.    if((number==table[0])&&(number1==table[1])&&(number2==table[2])&&(number3!=table[3]))
  192.       {
  193.       printf("Bet one won. Winnings=%.2f\nBet two won. Winnings=%.2f\nBet three won. Winnings=%.2f\nTotal winnings=%.2f\n",
  194.       bet[0]*2, bet[1]*2, bet[2]*2, ((bet[0]*2)+(bet[1]*2)+(bet[2]*2))-bet[3]);
  195.       }
  196.      
  197.    if((number!=table[0])&&(number1==table[1])&&(number2==table[2])&&(number3==table[3]))
  198.       {
  199.       printf("Bet two won. Winnings=%.2f\nBet three won. Winnings=%.2f\nBet four won. Winnings=%.2f\nTotal winnings=%.2f\n",
  200.       bet[1]*2, bet[2]*2, bet[3]*2, ((bet[1]*2)+(bet[2]*2)+(bet[3]*2))-bet[0]);
  201.       }
  202.      
  203.    if((number==table[0])&&(number1!=table[1])&&(number2==table[2])&&(number3==table[3]))
  204.       {
  205.       printf("Bet one won. Winnings=%.2f\nBet three won. Winnings=%.2f\nBet four won. Winnings=%.2f\nTotal winnings=%.2f\n",
  206.       bet[0]*2, bet[2]*2, bet[3]*2, ((bet[0]*2)+(bet[2]*2)+(bet[3]*2))-bet[1]);
  207.       }
  208.      
  209.    if((number==table[0])&&(number1==table[1])&&(number2!=table[2])&&(number3=table[3]))
  210.       {
  211.       printf("Bet one won. Winnings=%.2f\nBet two won. Winnings=%.2f\nBet four won. Winnings=%.2f\nTotal winnings=%.2f\n",
  212.       bet[0]*2, bet[1]*2, bet[3]*2, ((bet[0]*2)+(bet[1]*2)+(bet[3]*2))-bet[2]);
  213.       }
  214. }