<mosaic.cnfolio.com>
PROGRAM
  1. /* START
  2.    Initialise bet inputs to 1234
  3.    Initialise bet results as null
  4.    Initialise double zero as 37
  5.    Initialise double zero string as 00
  6.    Initialise money to 0
  7.    Initialise bets won to 0
  8.    Initialise bets lost to 0
  9.    Initialise bet 5 to 1234
  10.    
  11.    Scan in 8 inputs, 4 bets and 4 money amounts
  12.    Initialise random number generation
  13.    Print a welcome message
  14.    
  15.    
  16.    Convert the 4 string inputs into intergers
  17.    Generate 4 random intergers for bet results
  18.    Convert the 4 random bet results to strings
  19.    
  20.    IF the 5th bet DOES NOT equal 1234
  21.       THEN
  22.          PRINT an error message informing the user they have input too many bets
  23.       THEN
  24.          EXIT the program
  25.    END IF
  26.    
  27.    IF bet 1, bet 2, bet 3 or bet 4 EQUAL 1234
  28.       THEN
  29.          PRINT an error message informing the user they have not input enough bets
  30.       THEN
  31.          EXIT the program
  32.    END IF
  33.    
  34.    IF bet 1, bet 2, bet 3 or bet 4 are HIGHER than 36
  35.       THEN
  36.          PRINT an error message informing the user that the bet number is too low
  37.       THEN
  38.          EXIT the program
  39.    END IF
  40.    
  41.    IF bet 1, bet 2, bet 3 or bet 4 are LESS than 0
  42.       THEN
  43.          PRINT an error message informing the user that the bet number is too low
  44.       THEN
  45.          EXIT the program
  46.    END IF
  47.    
  48.    IF money 1, money 2, money 3 or money 4 are EQUAL too OR LESS than zero
  49.       THEN
  50.          PRINT an error message informing the user that they can't make a bet of zero or less
  51.       THEN
  52.          EXIT the program
  53.    END IF
  54.    
  55.    WHILE times ran is LESS than 4
  56.       IF any of the bet results equal 37
  57.          THEN
  58.             SET the bet result to 00
  59.       END IF
  60.       
  61.    END WHILE
  62.    
  63.    WHILE number of bet rolls is less than 4
  64.       IF the bet number matches the rolls
  65.          THEN
  66.             PRINT a congratulations message
  67.          THEN
  68.             PRINT the bet number and bet result
  69.          THEN
  70.             PRINT the amount of money they have won
  71.          THEN
  72.             Increment the bet counter by 1
  73.          THEN
  74.             ADD the money won to the total
  75.          THEN
  76.             PRINT the total money made/loss so far
  77.       ELSE IF the bet number does not match the roll
  78.          THEN
  79.             PRINT a message informing the user of the loss
  80.          THEN
  81.             PRINT the bet number and bet result
  82.          THEN
  83.             PRINT the bet loss
  84.          THEN
  85.             SUBTRACT the bet from the winning total
  86.          THEN
  87.             PRINT the total money made/loss so far
  88.       ELSE
  89.          THEN
  90.             PRINT an error message informing the user that something has gone wrong with the bet
  91.       END IF
  92.    END WHILE
  93.    
  94.    PRINT a message informing thanking the player for playing
  95.    PRINT all 4 bets placed by the user
  96.    PRINT what all 4 bets rolled
  97.    PRINT how many bets the player won/lost
  98.    PRINT how much the player bet in total
  99.    PRINT the total win loss for the player
  100. END
  101. */
  102. #include <stdio.h>
  103. #include <math.h>
  104. #include <stdlib.h>
  105. #include <time.h>
  106. #include <string.h>
  107.  
  108. int main(void)
  109. {
  110. char bet1[] = {"1234"}, bet2[] = {"1234"}, bet3[] = {"1234"} , bet4[] = {"1234"}; /* These are initialised to 1234 as an error check */
  111. char charbetresult1[] = {"\0"}, charbetresult2[] = {"\0"}, charbetresult3[] = {"\0"}, charbetresult4[] = {"\0"}; /*These are initialised with a null character*/
  112. char doublezero[] = {"37"}, setdoublezero[] = {"00"};
  113. int intbet1, intbet2, intbet3, intbet4;
  114. int betresult1, betresult2, betresult3, betresult4, betswon, betslost, bet5fail;
  115. int money1, money2, money3, money4, moneywon;
  116. moneywon = 0, betswon = 0, betslost = 0, bet5fail = 1234; /* Bet5fail is used to make sure there are not too many inputs */
  117.  
  118.  
  119.    scanf("%s %d %s %d %s %d %s %d %d", bet1, &money1, bet2, &money2, bet3, &money3, bet4, &money4, &bet5fail); /* Scanning the inputs */
  120.    srand( time( 0 ) );   /* Here random is defined as the current time */
  121.    printf("Welcome to American Roulette, thank you for your bets. Generating your results now...\n\n");
  122.    
  123.    sscanf(bet1, "%d", &intbet1); /* This is the bigger brother of scanf, I am using it convert a string to an integer for comparison purposes */
  124.    sscanf(bet2, "%d", &intbet2);
  125.    sscanf(bet3, "%d", &intbet3);
  126.    sscanf(bet4, "%d", &intbet4);
  127.      
  128.    betresult1 = rand() % 38; /* Generates the bets as integers from 0 to 37, 0-36 for integers and 37 is used to handle Double Zero */
  129.    betresult2 = rand() % 38;
  130.    betresult3 = rand() % 38;
  131.    betresult4 = rand() % 38;
  132.    
  133.    sprintf(charbetresult1, "%d", betresult1); /* Converts the bet result to a string, used for handling 37 & Double Zero */
  134.    sprintf(charbetresult2, "%d", betresult2);
  135.    sprintf(charbetresult3, "%d", betresult3);
  136.    sprintf(charbetresult4, "%d", betresult4);
  137.    if(bet5fail != 1234)
  138.    {
  139.    printf("Too many inputs! You have entered 9 (or more) input numbers");
  140.    exit(EXIT_FAILURE);
  141.    }
  142.    if(intbet1 == 1234 || intbet2 == 1234 || intbet3 == 1234 || intbet4 == 1234) /* Default bet values are set to 1234, if any of them are still 124 at th3is point, it is assumed that they have not been inputted */
  143.    {
  144.     printf("One (or more) inputs has not been entered correctly, maybe you haven't entered 4 bets?");
  145.     exit(EXIT_FAILURE);
  146.    }
  147.    if(intbet1 > 36 || intbet2 > 36 || intbet3 > 36 || intbet4 > 36) /* Makes sure that the bets aren't over the maximum number of 36  */
  148.    {
  149.    printf("One (or more) of your bets is higher than exists on a roulette table, the maximum is 36. You have entered %d, %d, %d and %d.", intbet1, intbet2, intbet3, intbet4);
  150.     exit(EXIT_FAILURE); /*Exits if they are over 36, and doesn't run the rest of the program */
  151.    }
  152.    if(intbet1 < 0 || intbet2 < 0 || intbet3 < 0 || intbet4 < 0) /* Makes sure that the bets aren't under 0. */
  153.    {
  154.    printf("You can't use negative numbers on a roulette table, you have entered %d, %d, %d and %d", intbet1, intbet2, intbet3, intbet4);
  155.    exit(EXIT_FAILURE); /* Exits if they are */
  156.    }
  157.    if(money1 <= 0 || money2 <= 0 || money3 <= 0 || money4 <= 0) /* Makes sure they are not placing any bets of 0 */
  158.    {
  159.    printf("Come on now, don't be a stingy bastard, you can't make a bet of 0 or less.");
  160.    exit(EXIT_FAILURE); /* Exits if they are being stingy and not placing any money bets */
  161.    }
  162.    
  163.    if(strcmp(charbetresult1, doublezero) == 0) /* Compares the bet result against '37' */
  164.    {
  165.         strcpy(charbetresult1, setdoublezero); /* Sets 37 to 00 if the IF statement is true */
  166.    }
  167.    if(strcmp(charbetresult2, doublezero) == 0)
  168.     {
  169.         strcpy(charbetresult2, setdoublezero);
  170.     }
  171.     if(strcmp(charbetresult3, doublezero) == 0)
  172.     {
  173.         strcpy(charbetresult3, setdoublezero);
  174.     }
  175.     if(strcmp(charbetresult4, doublezero) == 0)
  176.     {
  177.         strcpy(charbetresult4, setdoublezero);
  178.     }
  179.    
  180.    if(strcmp(charbetresult1, bet1) == 0) /* Compares the bet against the result */
  181.        {
  182.       printf("\nIt's a christmas miracle! You won the first bet");
  183.       printf("\nYou placed a bet on %s, and it landed on %s!", bet1, charbetresult1);
  184.       printf("\nYou won 35x your original bet as result, %d to be exact", money1 * 36);
  185.       betswon++; /* Increments the win counter by one */
  186.       moneywon = moneywon + money1 * 36; /* Adds the total winnings (35x and the original bet) to the total */
  187.       printf("\nSo far you have won (or lost) %d\n", moneywon);
  188.       }
  189.    else if(strcmp(charbetresult1, bet1) != 0) /* Compares the bet against the result */
  190.        {
  191.       printf("\nYou lost the first bet, probably not for the last time");
  192.       printf("\nYou placed a bet on %s, and it unfortunatley landed on %s!", bet1, charbetresult1);
  193.       printf("\nSadly you lost your bet, which was %d", money1);
  194.       moneywon = moneywon - money1;
  195.       betslost++; /* Incremenets the loss counter by one */
  196.       printf("\nSo far you have won (or lost) %d\n", moneywon);
  197.       }
  198.    else
  199.    {
  200.    printf("Something went wrong with bet 1, maybe you didn't input a bet number?");
  201.    }
  202.    
  203.    if(strcmp(charbetresult2, bet2) == 0) /* Compares the bet against the result */
  204.        {
  205.       printf("\nIt's a christmas miracle! You won the second bet");
  206.       printf("\nYou placed a bet on %s, and it landed on %d!", bet2, betresult2);
  207.       printf("\nYou won 35x your original bet as result, %d to be exact", money2 * 36);
  208.       betswon++; /* Increments the win counter by one */
  209.       moneywon = moneywon + money2 * 36;
  210.       printf("\nSo far you have won (or lost) %d", moneywon);
  211.       }
  212.    else if(strcmp(charbetresult2, bet2) != 0) /* Compares the bet against the result */
  213.        {
  214.       printf("\nYou lost the second bet, probably not for the last time");
  215.       printf("\nYou placed a bet on %s, and it unfortunatley landed on %s!", bet2, charbetresult2);
  216.       printf("\nSadly you lost your bet, which was %d", money2);
  217.       moneywon = moneywon - money2;
  218.       betslost++;
  219.       printf("\nSo far you won (or lost) %d\n", moneywon);
  220.       }
  221.    else
  222.        {
  223.        printf("Something went wrong with bet 2, maybe you didn't input a bet number?");
  224.        }
  225.    if(strcmp(charbetresult3, bet3) == 0) /* Compares the bet against the result */
  226.        {
  227.       printf("\nIt's a christmas miracle! You won the third bet");
  228.       printf("\nYou placed a bet on %s, and it landed on %d!", bet3, betresult3);
  229.       printf("\nYou won 35x your original bet as result, %d to be exact", money3 * 36);
  230.       betswon++;
  231.       moneywon = moneywon + money3 * 36;
  232.       printf("\nSo far you have won (or lost) %d\n", moneywon);
  233.       }
  234.    else if(strcmp(charbetresult3, bet3) != 0) /* Compares the bet against the result */
  235.        {
  236.       printf("\nYou lost the third bet, probably not for the last time");
  237.       printf("\nYou placed a bet on %s, and it unfortunatley landed on %s!", bet3, charbetresult3);
  238.       printf("\nSadly you lost your bet, which was %d", money3);
  239.       moneywon = moneywon - money3;
  240.       betslost++;
  241.       printf("\nSo far you have won (or lost) %d\n", moneywon);
  242.       }
  243.    else
  244.        {
  245.        printf("Something went wrong with bet 3, maybe you didn't input a bet number?");
  246.        }
  247.    
  248.    if(strcmp(charbetresult4, bet4) == 0) /* Compares the bet against the result */
  249.        {
  250.       printf("\nIt's a christmas miracle! You won the fourth bet");
  251.       printf("\nYou placed a bet on %s, and it landed on %d!", bet4, betresult4);
  252.       printf("\nYou won 35x your original bet as result, %d to be exact", money4 * 36);
  253.       betswon++;
  254.       moneywon = moneywon + money4 * 36;
  255.       printf("\nSo far you have won (or lost) %d\n", moneywon);
  256.       }
  257.    else if(strcmp(charbetresult4, bet4) != 0) /* Compares the bet against the result */
  258.        {
  259.       printf("\nYou lost the fourth bet, probably not for the last time");
  260.       printf("\nYou placed a bet on %s, and it unfortunatley landed on %s!", bet4, charbetresult4);
  261.       printf("\nSadly you lost your bet, which was %d", money4);
  262.       moneywon = moneywon - money4;
  263.       betslost++;
  264.       printf("\nSo far you have won (or lost) %d\n", moneywon);
  265.       }
  266.     else
  267.        {
  268.        printf("Something went wrong with bet 4, maybe you didn't input a bet number?");
  269.        }
  270.    
  271.    printf("\n============================================");
  272.    printf("\nThanks for playing American Roulette, your final statistics are as follows ");
  273.    printf("\nYou placed four bets, Bet 1 on %s, Bet 2 on %s, Bet 3 on %s, Bet 4 on %s", bet1, bet2, bet3, bet4);
  274.    printf("\nThe results were;\nBet 1 rolled on %d, \nBet 2 rolled on %d,", betresult1, betresult2);
  275.    printf("\nBet 3 rolled on %d, \nBet 4 rolled on %d,", betresult3, betresult4);
  276.    printf("\n\nOut of the four bets placed, %d won and %d lost", betswon, betslost);
  277.    printf("\nYou placed a total bet amount of %d", money1 + money2 + money3 + money4);
  278.    printf("\nOverall, you made a total of win/loss of %d", moneywon);
  279.    
  280.   }