<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. START
  3.  
  4. Set pocket value to 0
  5. Set counter value to 0
  6. Set all the betting wagers to -1
  7.  
  8. WHILE Bets are less than 4
  9. GET the bet on number and betting wager
  10.  
  11. Convert the bet on numbers from strings to integers
  12.  
  13. IF Any of the bettting wagers are -1
  14.   THEN
  15.   Display the welcoming banner and betting instrucitions
  16. ELSE IF Any of the bet on numbers are higher than 36
  17.   THEN
  18.   Display 'You've bet on a number higher than 36 or tried to bet on a letter, please try again.'
  19. ELSE IF Any of the bet on numbers are less than 0
  20.   THEN
  21.   Display 'You've bet on a number less than 0, please try again'
  22. END IF
  23. ELSE IF any of the betting wagers are euqal to or less than 0
  24.   THEN
  25.   Display 'You've tried to bet negative or zero money, please try again'
  26. ElSE
  27.   THEN
  28.   Run the rest of the code
  29.  
  30. Start the random number generation with the current time
  31. Gerate the random numbers for spins
  32. Convert random 'spins' to strings
  33.  
  34. IF the spin is 37
  35.   THEN
  36.   Convert the spin to 00
  37.  
  38. IF The spin is the same as bet on number
  39.   THEN
  40.   Add bet value times 36 to the pocket varaible
  41.   Increase the counter by one
  42.   Display 'You won the 1st spin!  You bet [betting wager] on [bet on number].  The winning number was [the spin number] and won you [betting wager times 35].  Currently in your pocket you have [pocket variable].'
  43. ELSE IF The spin doesn't match the bet on number
  44.   THEN
  45.   Minus the betting wager from the pocket variable
  46.   Increase the counter by one
  47.   Display 'You lost the 1st spin.  You bet [betting wager] on [bet on number].  The winning number was [the spin numner], this didn't win you anything.  Currently in your pocket you have [pocket variable].'
  48. ELSE
  49.   THEN
  50.   Display 'Unknown error, check input and run again.'
  51. END WHILE
  52.  
  53. Display 'Overall your net earnings are [pocket variable]'
  54. Display 'Thank you for playing ! :)'
  55.  
  56.  
  57. END
  58. */
  59.  
  60. #include <stdio.h>
  61. #include <stdlib.h>
  62. #include <string.h>
  63. #include <time.h>
  64.  
  65. int main (void)
  66. {
  67.    int betval1, betval2, betval3, betval4; /*Integer values for the betting money, there are no string values.*/
  68.    int intbet1, intbet2, intbet3, intbet4; /*Ineger values for the betting numbers, so they can be checked for negaive or oo high values.*/
  69.    int intspin1, intspin2, intspin3, intspin4; /*Integer versions of the random spins to work with the rand() function*/
  70.    int counter, pocket;
  71.    char betno1[] = {"a"}, betno2[] = {"b"}, betno3[] = {"c"}, betno4[] = {"d"}; /*Bet numbers as character strings to allow for 00 functionality*/
  72.    char charspin1[] = {"a spin"}, charspin2[] = {"a spin"}, charspin3[] = {"a spin"}, charspin4[] = {"a spin"}; /*Character versions of the random spins, used for 00 functionality*/
  73.    char doublecheck[] = {"37"}, doublezero[] = {"00"} ; /*Used for swapping out the randomly generated '37' for a '00'*/
  74.    
  75.    pocket= 0;
  76.    counter = 0;
  77.    betval1 = -1;
  78.    betval2 = -1;   
  79.    betval3 = -1;
  80.    betval4 = -1;
  81.    
  82.    scanf("%s %d %s %d %s %d %s %d ", betno1, &betval1, betno2, &betval2, betno3, &betval3, betno4, &betval4);
  83.    
  84.    sscanf(betno1, "%d", &intbet1); /*This set of sscanf is converting the bet on number to intergers to be checked later on*/
  85.    sscanf(betno2, "%d", &intbet2);
  86.    sscanf(betno3, "%d", &intbet3);
  87.    sscanf(betno4, "%d", &intbet4);
  88.    
  89.    
  90.    if (betval1 == -1 || betval2 == -1 || betval3 == -1 || betval4 == -1)
  91.    {
  92.     printf("Welcome to Sofie Tyler's :                                                                \n");
  93.     printf("  #####                           ######                                                  \n");
  94.     printf(" #     #   ####  #####  ######    #     #  ####  #    # #      #####  ###### ##### ###### \n");
  95.     printf(" #        #    # #    # #         #     # #    # #    # #      #         #     #   #      \n");
  96.     printf(" #        #    # #    # #####     ######  #    # #    # #      #####     #     #   #####  \n"); /*This is an ASCII art banner that will display if no input is recived*/
  97.     printf(" #        #    # #    # #         #   #   #    # #    # #      #         #     #   #      \n");
  98.     printf(" #     #  #    # #    # #         #    #  #    # #    # #      #         #     #   #      \n");
  99.     printf("  #####    ####  #####  ######    #     #  ####   ####  ###### ######    #     #   ###### \n");
  100.     printf("                                                                                          \n");
  101.     printf("     *~*~~~*~~~~~*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*~~~~~*~~~*~*     \n");
  102.     printf("                                                                                          \n");
  103.     printf("   Please enter your bets now in the form of pairs of betting number and betting wager.   \n");
  104.     printf("  Valid betting numbers are 0 to 36 additionally the double zero, any amount can be bet.  \n");
  105.     printf("       If you keep seeing this message, check your input you should have 8 numbers.       \n");
  106.    }
  107.    else if (intbet1 > 36 || intbet2 > 36 || intbet3 > 36 || intbet4 > 36) /*This is taking the integer forms of the bets, and makes sure they are less*/
  108.     printf("You've bet on a number higher than 36, please try again.");
  109.    else if (intbet1 < 0 || intbet2 < 0 || intbet3 < 0 || intbet4 < 0) /*This is taking the integer forms of the bets*/
  110.     printf("You've bet on a number less than 0, please try again");
  111.    else if (betval1 <= 0 || betval2 <= 0 || betval3 <= 0 || betval4 <= 0) /*This is checking for negative and null money bet values*/
  112.     printf("You've tried to bet negative or zero money, please try again");
  113.    else
  114.    {   
  115.        
  116.        
  117.        srand(time(0));                     /*This starts the random number generation using the time*/
  118.    intspin1 = rand() %38;                  /*This Generates a random number between 0 and 37, it's capped at 37 to provide an extra number for the '00' value*/
  119.    sprintf(charspin1, "%d", intspin1);     /*This changes the randomly generated int version into a character string*/
  120.    intspin2 = rand() %38;
  121.    sprintf(charspin2, "%d", intspin2);
  122.    intspin3 = rand() %38;
  123.    sprintf(charspin3, "%d", intspin3);
  124.    intspin4 = rand() %38;
  125.    sprintf(charspin4, "%d", intspin4);
  126.    
  127.    if (strcmp(charspin1,doublecheck) == 0)  /*This compares the random spin value to the 'doublecheck' of 37*/
  128.        strcpy(charspin1, doublezero);       /*This changes the random spin value into the string from 'doublezero' of 00*/
  129.    if (strcmp(charspin2,doublecheck) == 0)
  130.        strcpy(charspin2, doublezero);
  131.    if (strcmp(charspin3,doublecheck) == 0)
  132.        strcpy(charspin3, doublezero);
  133.    if (strcmp(charspin4,doublecheck) == 0)
  134.        strcpy(charspin4, doublezero);   
  135.    
  136.  
  137.    if (strcmp(charspin1,betno1) == 0) /*Compares the bet number and random spin, running if they're 'true'*/
  138.     {pocket = pocket+betval1*36;
  139.     counter ++;
  140.        printf("You won the %dst spin!\n  You bet %d on %s.\n  The winning number was %s and won you %d.\n  Currently in your pocket you have %d.\n\n", counter, betval1, betno1, charspin1, betval1*35, pocket);}
  141.    else if (strcmp(charspin1,betno1) != 0) /*Does opposite of above if statement, used to create a closed set of code. This must run if the previous cannot*/
  142.     {pocket = pocket-betval1;
  143.      counter ++;
  144.        printf("You lost the %dst spin.\n  You bet %d on %s.\n  The winning number was %s, this didn't win you anything.\n  Currently in your pocket you have %d.\n\n", counter, betval1, betno1, charspin1, pocket);}
  145.  
  146.     if (strcmp(charspin2,betno2) == 0)
  147.     {pocket = pocket+betval2*36;
  148.      counter ++;
  149.        printf("You won the %dnd spin!\n  You bet %d on %s.\n  The winning number was %s and won you %d.\n  Currently in your pocket you have %d.\n\n", counter, betval2, betno2, charspin2, betval2*35, pocket);}
  150.    else if (strcmp(charspin2,betno2) != 0)
  151.     {pocket = pocket-betval2;
  152.      counter ++;
  153.        printf("You lost the %dnd spin.\n  You bet %d on %s.\n  The winning number was %s, this didn't win you anything.\n  Currently in your pocket you have %d.\n\n", counter, betval2, betno2, charspin2, pocket);}
  154.    
  155.    if (strcmp(charspin3,betno3) == 0)
  156.     {pocket = pocket+betval3*36;
  157.      counter ++;
  158.        printf("You won the %drd spin!\n  You bet %d on %s.\n  The winning number was %s and won you %d.\n  Currently in your pocket you have %d.\n\n", counter, betval3, betno3, charspin3, betval3*35, pocket);}
  159.    else if (strcmp(charspin3,betno3) != 0)
  160.     {pocket = pocket-betval3;
  161.     counter ++;
  162.        printf("You lost the %drd spin.\n  You bet %d on %s.\n  The winning number was %s, this didn't win you anything.\n  Currently in your pocket you have %d.\n\n", counter, betval3, betno3, charspin3, pocket);}
  163.    
  164.    if (strcmp(charspin4,betno4) == 0)
  165.     {pocket = pocket+betval4*36;
  166.      counter ++;
  167.        printf("You won the %dth spin!\n  You bet %d on %s.\n  The winning number was %s and won you %d.\n  Currently in your pocket you have %d.\n\n", counter, betval4, betno4, charspin4, betval4*35, pocket);}
  168.    else if (strcmp(charspin4,betno4) != 0)
  169.     {pocket = pocket-betval4;
  170.      counter ++;
  171.        printf("You lost the %dth spin.\n  You bet %d on %s.\n  The winning number was %s, this didn't win you anything.\n  Currently in your pocket you have %d.\n\n", counter, betval4, betno4, charspin4, pocket);}
  172.  
  173.    else
  174.     printf("Unknown error, check input and run again.");
  175.    
  176. printf("Overall your net earnings are %d\n", pocket);
  177. printf("Thank you for playing! :)");
  178.  
  179.      
  180. }}