<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. START
  3.    PROMPT player to enter four bet values and bet amounts
  4.    GET four bet values and bet amount pairs
  5.    IF number of bets inputted are not equal to four
  6.       THEN
  7.          DISPLAY error message which informs player to input four bet value and amount pairs
  8.       ELSE
  9.       continue with program
  10.    END IF
  11.    IF bet values and bet amounts are not positive intergers
  12.    AND IF bet values are not 00 OR ranging from 0 to 36
  13.       THEN
  14.          DISPLAY error message which informs player to input valid bet and amount values
  15.       ELSE
  16.          DISPLAY the four bet values and amount placed on each bet
  17.          Spin the roulette wheel using an American style roulette table which allow players to bet on 00
  18.          DISPLAY the winning value
  19.          IF any of the bet value is the same as the winning value
  20.             THEN
  21.                calculate the profit for the bet by multiplying the amount by 35
  22.                ADD the profit to the payout
  23.                THEN add the bet amount to the payout
  24.                   IF no bets are won
  25.                      THEN
  26.                         profit and payout is zero
  27.                   END IF     
  28.             ELSE
  29.                calculate the losing amount for the rest of the bets by adding the losing amounts together 
  30.           END IF
  31.      DISPLAY the total payout for winning bets
  32.          DISPLAY the total profit on winning bets
  33.          DISPLAY the total amount lost for losing bets
  34.          DISPLAY the net profit or losings for all four bets
  35.    END IF      
  36. END
  37. */
  38.  
  39. #include <stdio.h>
  40. #include <time.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <ctype.h>
  44.  
  45. int main(void)
  46. {
  47.    srand(time(0));            /*Randomise seed to allow the random function to generate a different random number each time*/
  48.    int winner = rand() % 38/*Generates a random number from 0 to 37 which acts as the winning values, 37 acts as value "00"*/
  49.  
  50.    /*Bet variables below defined as character with an array size of two characters to allow "00" to be inputted as a bet*/ 
  51.    char bet5[2];               
  52.    char bet6[2];
  53.    char bet7[2];
  54.    char bet8[2];
  55.    /*Bet variables below defined as integer and initialized as 37, the values of these will be converted from the string values of bet5 to bet8. If the bet is "00" the value will stay as 37 and wont be overwritten*/
  56.    int bet1 = 37
  57.    int bet2 = 37;
  58.    int bet3 = 37;
  59.    int bet4 = 37;
  60.    /*Double Zero variable which is a string consisting of 00, used as a comparison for "00" bets*/
  61.    char double0[]="00";   
  62.    /*Bet amount, bet payout, bet profits, bet losings and total payout, profit and losings variables defined as float and inialized as 0*/
  63.    float amount1 = 0;
  64.    float amount2 = 0;
  65.    float amount3 = 0;
  66.    float amount4 = 0;
  67.    float payout1 = 0;
  68.    float payout2 = 0;
  69.    float payout3 = 0;
  70.    float payout4 = 0;
  71.    float profit1 = 0;
  72.    float profit2 = 0;
  73.    float profit3 = 0;
  74.    float profit4 = 0;
  75.    float losings1 = 0;
  76.    float losings2 = 0;
  77.    float losings3 = 0;
  78.    float losings4 = 0;
  79.    float totalpayout = 0;
  80.    float totallosings = 0;
  81.    float totalprofit = 0;
  82.    /*The validate variable below is definded as integer and acts as a check rule and value will be set based on if a condition is true or false*/
  83.    int validate = 0
  84.    
  85.    /*Function below displays the welcome message that prompts player to enter bet values and amounts*/
  86.    printf("Welcome to Roulette, Please enter four number bets, inputting the bet value then the amount placed on the bet.\n\n");
  87.    
  88.    /*Functions below reads the bet values and amounts that the player inputs*/
  89.    scanf("%s", &bet5);     
  90.    scanf("%f", &amount1);
  91.    scanf("%s", &bet6);
  92.    scanf("%f", &amount2);
  93.    scanf("%s", &bet7);
  94.    scanf("%f", &amount3);
  95.    scanf("%s", &bet8);
  96.    scanf("%f", &amount4)
  97.    
  98.    /*The string compare functions below check if any of the bets are "00" by comparing the first two characters of double0 string and each value of bet5, bet6, bet7 and bet8 variables which are inputted by player.*/
  99.    if (strncmp(double0, bet5, 2))   /*Comparing double0 to bet5*/
  100.    {
  101.     bet1 = atoi(bet5);    /*The string value of bet5 is converted to interger and equates it to bet1 is bet5 is not"00". If bet5 is "00" then bet1 will stay as value 37*/          
  102.    }
  103.    if (strncmp(double0, bet6, 2))   /*Comparing double0 to bet6*/ 
  104.    {
  105.       bet2 = atoi(bet6);            /*The string value of bet6 is converted to interger and equates it to bet2 is bet5 is not"00". If bet6 is "00" then bet2 will stay as value 37*/
  106.    }
  107.    if (strncmp (double0, bet7, 2))  /*Comparing double0 to bet7*/
  108.    {
  109.       bet3 = atoi (bet7);        /*The string value of bet7 is converted to interger and equates it to bet3 is bet5 is not"00". If bet7 is "00" then bet3 will stay as value 37*/
  110.    }
  111.    if (strncmp (double0, bet8, 2))  /*Comparing double0 to bet8*/
  112.    {
  113.       bet4 = atoi (bet8);        /*The string value of bet8 is converted to interger and equates it to bet4 is bet5 is not"00". If bet8 is "00" then bet4 will stay as value 37*/
  114.    }
  115.    
  116.    /* The while loops below act as a validation method for bets entered, if the bets are not between 0 to 37 (as 37 is the "00" value) then validate variable becomes 1 which triggers the error message
  117.       I can use if statements here instead of while but i want to show that while statements can also be used*/
  118.    while (bet1<0 || bet1>37)
  119.    {
  120.          validate=1; break;
  121.    }
  122.    while (bet2<0 || bet2>37)
  123.    {
  124.          validate=1; break;
  125.    }
  126.    while (bet3<0 || bet3>37)
  127.    {
  128.          validate=1; break;
  129.    }
  130.    while (bet4<0 || bet4>37)
  131.    {
  132.          validate=1; break;
  133.    }
  134.    
  135.    /*If any bet amounts are not 1 or more then the validate variable is set to 1 which triggers the error message*/
  136.    if (amount1<=0)
  137.    {
  138.       validate=1;
  139.    }
  140.    if (amount2<=0)
  141.    {
  142.       validate=1;
  143.    }
  144.    if (amount3<=0)
  145.    {
  146.       validate=1;
  147.    }
  148.    if (amount4<=0)
  149.    {
  150.       validate=1;
  151.    }
  152.    
  153.    if (validate==0)  /*If there are no error cases and validate stays as value 0 then the program will continue*/
  154.    { 
  155.       /*Displays each bet and how much the user bet on each bet*/
  156.       if (bet1==37)
  157.       {
  158.          printf("You have bet %.2f on value 00\n", amount1);  
  159.       }
  160.       else
  161.       {
  162.          printf("You have bet %.2f on number %d\n", amount1, bet1);
  163.       }
  164.       if (bet2==37)
  165.       {
  166.          printf("You have bet %.2f on value 00\n", amount2);
  167.       }
  168.       else
  169.       {
  170.          printf("You have bet %.2f on number %d\n", amount2, bet2);
  171.       }
  172.       if (bet3==37)
  173.       {
  174.          printf("You have bet %.2f on value 00\n", amount3);
  175.       }
  176.       else
  177.       {
  178.          printf("You have bet %.2f on number %d\n", amount3, bet3);
  179.       }
  180.       if (bet4==37)
  181.       {
  182.          printf("You have bet %.2f on value 00\n", amount4);
  183.       }
  184.       else
  185.       {
  186.          printf("You have bet %.2f on number %d\n", amount4, bet4);
  187.       }
  188.      
  189.       /*Displays the winning value, if the generated number is 37 then "The winning value is "00" is displayed"*/
  190.       if (winner==37)
  191.       {
  192.          printf("The winning value is 00\n");
  193.       }
  194.       else
  195.       {
  196.          printf("The winning number is %d\n", winner);
  197.       }
  198.      
  199.       /*Calculating and displaying payouts and profits on each bet, payout of each bet is calculated by multiplying the amount bet by 35 and adding the amount bet to it, if trhe bet is won.
  200.       Profit calculated by minusing the amount bet from the payout of the winning bet, if bet lost the amount loss is the same as amount bet and message is displayed to inform player that he lost on that bet*/
  201.      
  202.       if (bet1==winner)
  203.       {
  204.          payout1=amount1+(amount1*35);              
  205.          profit1=payout1-amount1;                           
  206.          printf("You have won %.2f on bet 1\n",payout1);   
  207.       }
  208.       else
  209.       {
  210.          losings1=amount1;
  211.          printf("You have lost %.2f on bet 1\n",losings1)
  212.       }   
  213.       if (bet2==winner)
  214.       {
  215.          payout2=amount2+(amount2*35);
  216.          profit2=payout2-amount2;
  217.          printf("You have won %.2f on bet 2\n",payout2);
  218.       }
  219.       else
  220.       {
  221.          losings2=amount2;
  222.          printf("You have lost %.2f on bet 2\n", losings2);
  223.       }
  224.       if (bet3==winner)
  225.       {
  226.          payout3=amount3+(amount3*35);
  227.          profit3=payout3-amount3;
  228.          printf("You have won %.2f on bet 3\n",payout3);
  229.       }
  230.       else
  231.       {
  232.          losings3=amount3;
  233.          printf("You have lost %.2f on bet 3\n",losings3);
  234.       }
  235.       if (bet4==winner)
  236.       {
  237.          payout4=amount4+(amount4*35);
  238.          profit4=payout4-amount4;
  239.          printf("You have won %.2f on bet 4\n",payout4);
  240.       }
  241.       else
  242.       {
  243.          losings4=amount4;
  244.           printf("You have lost %.2f on bet 4\n\n",losings4);
  245.       }
  246.      
  247.       /*Calculating and displaying total payouts, profits and losses on all four bets*/
  248.       totalpayout=payout1 + payout2 + payout3 + payout4;
  249.       totalprofit=profit1 + profit2 + profit3 + profit4;
  250.       totallosings=losings1 + losings2 + losings3 + losings4;
  251.       printf("The total payout is %.2f\n", totalpayout);
  252.       printf("The total profit is %.2f\n", totalprofit);
  253.          if (totalpayout==0)
  254.          {
  255.             printf("Unlucky, you have lost every bet\n");   /*If player does not recieve any payout then message displayed to notify player that he has lost on each bet*/
  256.          }
  257.       printf("The total losings are %.2f\n", totallosings);
  258.       if (totalprofit>totallosings)
  259.       {
  260.          printf("Your net profit is %.2f\n",totalprofit-totallosings);  /*The net loss/profit is calculated by minusing the total losings from total profit, if there was a profit then a message will display how much the player has made over all bets*/
  261.       }
  262.       else
  263.       { 
  264.          printf("Your net loss is %.2f\n",-(totalprofit-totallosings));   /*If there wasn't a profit then a message will display how much the player has lost over all bets*/
  265.       }
  266.    }
  267.    /*Error message displayed if any invalid data is entered and the check rule is triggered, i.e. validate variable is set to 1*/
  268.    else
  269.    {
  270.       printf("Error Invalid Inputs!, Please ensure you have entered bets which include 00 and numbers between 0 and 36.\nAlso ensure you have entered valid amounts for the bets.\n");
  271.    }     
  272. }