<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. START
  3.    
  4.    GET the first bet
  5.    GET the first amount
  6.    GET the second bet
  7.    GET the second amount
  8.    GET the third bet
  9.    GET the third amount
  10.    GET the fourth bet
  11.    GET the fourth amount
  12.    
  13.    Spin the American-Style roulette wheel with a double zero on the end.
  14.    Land on a random number between 0 and 37, with 37 being the double zero.
  15.      
  16.   IF The fourth bet is greater than 37
  17.          THEN
  18.          Display an error for missing input
  19.          Exit the program
  20.   END IF
  21.    
  22.   IF The fourth amount is equal or less than 0
  23.          THEN
  24.          Display an error for missing input
  25.          Exit the program
  26.   END IF
  27.    
  28.   IF The first bet is greater than 37
  29.          THEN
  30.          Display an error for an incorrect bet number
  31.          Exit the program
  32.     ELSE IF the first bet is less than or equal to 0
  33.        THEN
  34.          Display an error for an incorrect bet amount
  35.          Exit the program
  36.    END IF
  37.    END IF
  38.    
  39.   IF The second bet is greater than 37
  40.          THEN
  41.          Display an error for an incorrect bet number
  42.          Exit the program
  43.     ELSE IF the second bet is less than or equal to 0
  44.        THEN
  45.          Display an error for an incorrect bet amount
  46.          Exit the program
  47.    END IF
  48.    END IF
  49.  
  50.   IF The third bet is greater than 37
  51.          THEN
  52.          Display an error for an incorrect bet number
  53.          Exit the program
  54.     ELSE IF the first bet is less than or equal to 0
  55.        THEN
  56.          Display an error for an incorrect bet amount
  57.          Exit the program
  58.    END IF
  59.    END IF
  60.    
  61.    IF The fourth bet is greater than 37
  62.          THEN
  63.          Display an error for an incorrect bet number
  64.          Exit the program
  65.     ELSE IF the second bet is less than or equal to 0
  66.        THEN
  67.          Display an error for an incorrect bet amount
  68.          Exit the program
  69.    END IF
  70.    END IF
  71.  
  72.  
  73.    IF The first amount is equal to or less than 0
  74.      THEN
  75.          Display an error that this is an invalid amount
  76.        Exit the program
  77.    END IF
  78.    
  79.    IF The second amount is equal to or less than 0
  80.      THEN
  81.          Display an error that this is an invalid amount
  82.        Exit the program
  83.    END IF
  84.  
  85.    IF The third amount is equal to or less than 0
  86.      THEN
  87.          Display an error that this is an invalid amount
  88.        Exit the program
  89.    END IF
  90.    
  91.    IF The fourth amount is equal to or less than 0
  92.      THEN
  93.          Display an error that this is an invalid amount
  94.        Exit the program
  95.    END IF
  96.      
  97.   Display Welcome to Roulette greeting messages
  98.    
  99.   IF the first bet is equal to the winning number
  100.       SET the win1 variable to the first amount multiplied by 35
  101.       SET the stake1 variable to the win1 plus the first amount
  102.          THEN
  103.             Display bet number
  104.             Display bet amount
  105.             Display the winning number
  106.             Display the payout
  107.             Display the subtotal
  108.          ELSE
  109.       SET win1 to the first amount multiplied by -1
  110.       SET stake1 to equal win1
  111.             Display bet number
  112.             Display bet amount
  113.             Display the winning number
  114.             Display the amount you have lost
  115.             Display the subtotal
  116.   END IF
  117.  
  118.      IF The second bet is equal to the winning number
  119.       SET win2 to the second amount multiplied by 35
  120.       SET stake2 to win2 plus the second amount
  121.          THEN
  122.             Display bet number
  123.             Display bet amount
  124.             Display the winning number
  125.             Display the payout
  126.             Display the subtotal
  127.          ELSE
  128.       SET win2 to the second amount multiplied by -1
  129.       SET stake2 to equal win2
  130.             Display bet number
  131.             Display bet amount
  132.             Display the winning number
  133.             Display the amount you have lost
  134.             Display the subtotal
  135.    END IF
  136.      
  137. IF The third bet is equal to the winning number
  138.       SET win3 to the third amount multiplied by 35
  139.       SET stake3 to win3 plus the third amount
  140.          THEN
  141.             Display bet number
  142.             Display bet amount
  143.             Display the winning number
  144.             Display the payout
  145.             Display the subtotal
  146.          ELSE
  147.       SET win3 to the third amount multiplied by -1
  148.       SET stake3 to equal win3
  149.             Display bet number
  150.             Display bet amount
  151.             Display the winning number
  152.             Display the amount you have lost
  153.             Display the subtotal
  154.    END IF
  155.          
  156. IF The fourth bet is equal to the winning number
  157.       SET win4 to the fourth amount multiplied by 35
  158.       SET stake4 to win4 plus the fourth amount
  159.          THEN
  160.             Display bet number
  161.             Display bet amount
  162.             Display the winning number
  163.             Display the payout
  164.             Display the subtotal
  165.          ELSE
  166.       SET win4 to the fourth amount multiplied by -1
  167.       SET stake4 to equal win4
  168.             Display bet number
  169.             Display bet amount
  170.             Display the winning number
  171.             Display the amount you have lost
  172.             Display the subtotal
  173.    END IF
  174.  
  175.    SET loss1 to amount2 plus amount3 plus amount4
  176.    SET loss2 to amount1 plus amount3 plus amount4
  177.    SET loss3 to amount1 plus amount2 plus amount4
  178.    SET loss4 to amount1 plus amount2 plus amount3
  179.    SET total to all the amounts added together
  180.        
  181.    IF bet1 wins and the rest lose
  182.       THEN
  183.         Display Total loss where loss is calculated with loss1
  184.         Display Total profit where profit is calculated with stake1-loss1
  185.    END IF
  186.      
  187.    IF bet2 wins and the rest lose
  188.       THEN
  189.         Display Total loss where loss is calculated with loss2
  190.         Display Total profit where profit is calculated with stake2-loss2
  191.    END IF
  192.      
  193.    IF bet3 wins and the rest lose
  194.       THEN
  195.         Display Total loss where loss is calculated with loss3
  196.         Display Total profit where profit is calculated with stake3-loss3
  197.    END IF
  198.      
  199.    IF bet4 wins and the rest lose
  200.       THEN
  201.         Display Total loss where loss is calculated with loss4
  202.         Display Total profit where profit is calculated with stake4-loss4
  203.    END IF
  204.        
  205.    IF all bets lose
  206.         Display You have not won this time.
  207.         Display The amount you have lost.
  208.   END IF
  209.    
  210. END
  211. */
  212.  
  213. #include <stdio.h>
  214. #include <time.h>
  215.  
  216. int main ( void )
  217. {
  218.    /*Variables*/
  219.    int bet1;
  220.    int bet2;
  221.    int bet3;
  222.    int bet4;
  223.    int amount1;
  224.    int amount2;
  225.    int amount3;
  226.    int amount4;
  227.    int randnumb;
  228.    int win1;
  229.    int win2;
  230.    int win3;
  231.    int win4;
  232.    int loss1;
  233.    int loss2;
  234.    int loss3;
  235.    int loss4;
  236.    int stake1;
  237.    int stake2;
  238.    int stake3;
  239.    int stake4;
  240.    int total;
  241.  
  242.    /*Input*/
  243.    scanf("%d %d %d %d", &bet1, &amount1, &bet2, &amount2);
  244.    scanf("%d %d %d %d", &bet3, &amount3, &bet4, &amount4);
  245.  
  246.    /*Generate's a random number's*/
  247.    srand( time(0) );
  248.    randnumb = rand() %38;
  249.    /*My random number generator is set to %38 as this allows 37, which is my double-zero.*/
  250.    
  251.    /*Error's for missing input.*/
  252.    if (bet4 > 37){
  253.       printf("Error: Please enter four numbers as either 37 or under for your bets!\n");
  254.       printf("Error: Please enter four correct amounts that you wish to place on your bets!\n");
  255.       exit(0);
  256.       }
  257.      
  258.    if (amount4 <= 0){
  259.       printf("Error: Please enter either 37 or below for your four bets!\n");
  260.       printf("Error: Please enter four correct amounts that you wish to place on your bets!\n");
  261.       exit(0);
  262.       }
  263.        
  264.    /*When testing for leaving blank missing input, it always jumped to the fourth error
  265.      of either bet four or amount four, so I decided to use these to create the error's missing inputs.*/
  266.    
  267.    /*I created these IF-ELSE-IF statements to detect for negative numbers under 0 or positive
  268.      numbers over 37, which are not allowed as bet numbers.*/
  269.    if (bet1 > 37){
  270.          printf("Error: Please enter a number at either 37 or less for bet1!\n");
  271.          printf("Enter correct numbers at either 37 or under and run the program again.");
  272.          exit(0);
  273.       }else if (bet1 < 0){
  274.          printf("Error: Please enter a positive number for bet1!\n");
  275.          printf("Enter correct numbers at either 37 or under and run the program again.");
  276.          exit(0);
  277.      
  278.    }if (bet2 > 37){
  279.          printf("Error: Please enter a number at either 37 or less for bet2!\n\n");
  280.          printf("Enter correct numbers at either 37 or under and run the program again.");
  281.          exit(0);
  282.       }else if (bet2 < 0){
  283.          printf("Error: Please enter a positive number for bet2!\n");
  284.          printf("Enter correct numbers at either 37 or under and run the program again.");
  285.          exit(0);
  286.      
  287.    }if (bet3 > 37){
  288.           printf("Error: Please enter a number at either 37 or less for bet3!\n\n");
  289.          printf("Enter correct numbers at either 37 or under and run the program again.");
  290.          exit(0);
  291.       }else if (bet3 < 0){
  292.          printf("Error: Please enter a positive number for bet3!\n");
  293.          printf("Enter correct numbers at either 37 or under and run the program again.");
  294.          exit(0)
  295.    
  296.    }if (bet4 > 37){
  297.          printf("Error: Please enter a number at either 37 or less for bet4!\n\n");
  298.          printf("Enter correct numbers at either 37 or under and run the program again.");
  299.          exit(0);
  300.       }else if (bet4 < 0){
  301.          printf("Error: Please enter a positive number for bet4!\n");
  302.          printf("Enter correct numbers at either 37 or under and run the program again.");
  303.          exit(0);
  304.       /*I included the Exit function so that the program does not continue and requires the player
  305.         to fix their mistake and play again.*/
  306.    }
  307.    
  308.    if (amount1 <= 0){
  309.       printf("Error: Please enter an amount greater than zero!\n");
  310.       exit(0);
  311.    }if (amount2 <= 0){
  312.       printf("Error: Please enter an amount greater than zero!\n");
  313.       exit(0);
  314.    }if (amount3 <= 0){
  315.       printf("Error: Please enter an amount greater than zero!\n");
  316.       exit(0);
  317.    }if (amount4 <= 0){
  318.       printf("Error: Please enter an amount greater than zero!\n");
  319.       exit(0);
  320.       }
  321.    /*These IF statements are to detect for correct amounts which look for any amount input at zero or less
  322.      which will then trigger the error.*/
  323.          
  324.    /*Display's welcome message*/
  325.    printf( "Welcome to roulette!\n");
  326.    
  327.    /*For the calcualtion I stored the bet amount multiplied by 35, the payout
  328.      into a variable called win1 and so on for each bet. This was so I could easily call
  329.      it in the IF statements below. As-well as this, I then stored what was won in win1
  330.      and added it to it's respective amount, so amount1, which was then stored in the variable
  331.      stake1 to calculate the total winnings which this time included the stake as well
  332.      and then this was displayed as the subtotal.*/
  333.    
  334.    /*These IF-ELSE statements will see if a bet has won or lost and display the correct results
  335.      depending on the outcome.*/
  336.    if ( bet1 == randnumb ){
  337.       win1 = amount1*35;
  338.       stake1 = win1 + amount1;
  339.          printf("\nBet 1:");
  340.          printf("\nYour bet number: %d", bet1);
  341.          printf("\nYour bet amount: %d", amount1);
  342.          printf("\nThe Winning Number: %d", randnumb);
  343.          printf("\nThis bet has won! - The amount you have won for this bet is: %d", win1);
  344.        printf("\nYour new subtotal (Including the stake): %d\n", stake1);
  345.          }else{
  346.          win1 = amount1*(-1); /*For each loss, I multiplied the amount by -1 to turn it into a negative
  347.          number when the calculation of adding stakes below takes place to display the correct amount.*/
  348.          stake1 = win1;
  349.             printf("\nBet 1:");
  350.             printf("\nYour bet number: %d", bet1);
  351.             printf("\nYour bet amount: %d", amount1);
  352.             printf("\nThe Winning Number: %d", randnumb);
  353.             printf("\nThis bet has lost! - The amount you have lost for this bet is: %d", amount1);
  354.             printf("\nYour new subtotal: %d\n", stake1);
  355.       }
  356.      
  357.    if ( bet2 == randnumb ){
  358.       win2 = amount2*35;
  359.       stake2 = win2 + amount2;
  360.          printf("--------------------------------------------------------------------------------------");
  361.          printf("\nBet 2:");
  362.          printf("\nYour bet number: %d", bet2);
  363.          printf("\nYour bet amount: %d", amount2);
  364.          printf("\nThe Winning Number: %d", randnumb);
  365.          printf("\nThis bet has won! - The amount you have won for this bet is: %d", win2);
  366.          printf("\nYour new subtotal (Including the stake): %d\n", stake1+stake2);
  367.          }else{
  368.          win2 = amount2*(-1);
  369.          stake2 = win2;
  370.             printf("--------------------------------------------------------------------------------------");
  371.             printf("\nBet 2:");
  372.             printf("\nYour bet number: %d", bet2);
  373.             printf("\nYour bet amount: %d", amount2);
  374.             printf("\nThe Winning Number: %d", randnumb);
  375.         printf("\nThis bet has lost! - The amount you have lost for this bet is: %d", amount2);
  376.             printf("\nYour new subtotal: %d\n", stake1+stake2);
  377.       }
  378.      
  379.    if ( bet3 == randnumb ){
  380.     win3 = amount3*35;
  381.       stake3 = win3 + amount3;
  382.          printf("--------------------------------------------------------------------------------------");
  383.          printf("\nBet 3:");
  384.          printf("\nYour bet number: %d", bet3);
  385.          printf("\nYour bet amount: %d", amount3);
  386.          printf("\nThe Winning Number: %d", randnumb);
  387.          printf("\nThis bet has won! - The amount you have won for this bet is: %d", win3);
  388.          printf("\nYour new subtotal (Including the stake): %d\n", stake1+stake2+stake3);
  389.          }else{
  390.          win3 = amount3*(-1);
  391.          stake3 = win3;
  392.             printf("--------------------------------------------------------------------------------------");
  393.             printf("\nBet 3:");
  394.             printf("\nYour bet number: %d", bet3);
  395.             printf("\nYour bet amount: %d", amount3);
  396.             printf("\nThe Winning Number: %d", randnumb);
  397.             printf("\nThis bet has lost! - The amount you have lost for this bet is: %d", amount3);
  398.             printf("\nYour new subtotal: %d\n", stake1+stake2+stake3);
  399.       }
  400.    
  401.    if ( bet4 == randnumb ){
  402.       win4 = amount4*35;
  403.       stake4 = win4 + amount4;
  404.          printf("--------------------------------------------------------------------------------------");
  405.          printf("\nBet 4:");
  406.          printf("\nYour bet number: %d", bet4);
  407.          printf("\nYour bet amount: %d", amount4);
  408.          printf("\nThe Winning Number: %d", randnumb);
  409.          printf("\nThis bet has won! - The amount you have won for this bet is: %d", win4);
  410.          printf("\nYour new subtotal (Including the stake): %d\n", stake1+stake2+stake3+stake4);
  411.          printf("--------------------------------------------------------------------------------------");
  412.          }else{
  413.          win4 = amount4*(-1);
  414.          stake4 = win4;
  415.             printf("--------------------------------------------------------------------------------------");
  416.             printf("\nBet 4:");
  417.             printf("\nYour bet number: %d", bet4);
  418.             printf("\nYour bet amount: %d", amount4);
  419.             printf("\nThe Winning Number: %d", randnumb);
  420.             printf("\nThis bet has lost! - The amount you have lost for this bet is: %d", amount4);
  421.             printf("\nYour new subtotal: %d\n", stake1+stake2+stake3+stake4);
  422.             printf("--------------------------------------------------------------------------------------");
  423.       }
  424.     /*I used IF-ELSE statements to check if the bets equal the random number to show how much
  425.       has been won and then if they don't match the random number, how much they have lost*/
  426.      
  427.     /*Setting loses to their correct amounts*/
  428.     loss1 = amount2+amount3+amount4;
  429.     loss2 = amount1+amount3+amount4;
  430.     loss3 = amount1+amount2+amount4;
  431.     loss4 = amount1+amount2+amount3;
  432.     total = stake1+stake2+stake3+stake4;
  433.     /*This section of code allows me to set the loss variables to however much has been lost
  434.       for each bet which is just each amount that has lost added up. */
  435.    
  436.     /*If bet1 wins and the rest lose.*/
  437.     if (bet1 == randnumb && bet2 != randnumb && bet3 != randnumb && bet4 != randnumb){
  438.         printf("\nResult:");
  439.          printf("\nThe total you have lost from this bet is: %d", loss1);
  440.          printf("\nThe total profit you have earned from this bet is: %d", stake1-loss1);
  441.       }
  442.    
  443.     /*If bet2 wins and the rest lose.*/
  444.     if (bet2 == randnumb && bet1 != randnumb && bet3 != randnumb && bet4 != randnumb){
  445.         printf("\nResult:");
  446.          printf("\nThe total you have lost from this bet is: %d", loss2);
  447.          printf("\nThe total profit you have earned from this bet is: %d", stake2-loss2);
  448.       }
  449.      
  450.     /*If bet3 wins and the rest lose.*/ 
  451.     if (bet3 == randnumb && bet1 != randnumb && bet2 != randnumb && bet4 != randnumb){
  452.         printf("\nResult:");
  453.          printf("\nThe total you have lost from this bet is: %d", loss3);
  454.          printf("\nThe total profit you have earned from this bet is: %d", stake3-loss3);
  455.       }
  456.    
  457.     /*If bet4 wins and the rest lose.*/
  458.     if (bet4 == randnumb && bet1 != randnumb && bet2 != randnumb && bet3 != randnumb){
  459.         printf("\nResult:");
  460.          printf("\nThe total you have lost from this bet is: %d", loss4);
  461.          printf("\nThe total profit you have earned from this bet is: %d", stake4-loss4);
  462.       }
  463.      
  464.     /*For different bets winning and the rest losing, I just used IF statements with multiple
  465.       conditions where for example, if bet1 had won then the rest would lose shown by using
  466.       != - as well as this the total profit earned from a win is then calculated through
  467.       taking the stake variables, which have the win, which is: (amount multiplied by 35)
  468.       stored inside of them and then the amount of that bet added on top to include the stake
  469.       and took the loss variables away from the stake variables to work out the total.
  470.       The loss variables are just the different amounts for the bets that lose added up together
  471.       to subtract that from the stake variables to get the total.*/
  472.    
  473.     /*If all bets lose.*/
  474.     if (bet1 != randnumb && bet2 != randnumb && bet3 != randnumb && bet4 != randnumb){
  475.          printf("\nResult:");
  476.          printf("\nYou have not won this time, play again!");
  477.          printf("\nThe total amount that you have bet: %d", total);
  478.          printf("\nThe total amount you have lost for all four bets: %d", total);
  479.       }
  480.    
  481.  
  482. }