<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. Psuedo Code:
  3.  
  4. START
  5.    Populate American roulette style pockets (00, 0 and 1-36)
  6.    Obtain the four numbers that have been bet on.
  7.    Obtain the four bet amounts.
  8.    Set counter equal to 0.
  9.   WHILE counter equals 0 and is less than 4.
  10.       IF The bet number corresponding to the counter is not a American roulette style pocket.
  11.          THEN
  12.             Turn on the error indicator.
  13.       END IF
  14.       IF The bet amounts contain punctuation marks.
  15.          THEN
  16.             Turn on the error indicator.
  17.       END IF
  18.       IF The bet amounts are not positive integers greater than 0.
  19.          THEN
  20.             Turn on the error indicator.
  21.       END IF
  22.    END WHILE
  23.       IF error indicator is on.
  24.          THEN
  25.             Display error messages regarding the criteria for valid input bet numbers and bet amounts.
  26.       END IF
  27.       ELSE
  28.          THEN
  29.             Generate a  random winning pocket (includes 0, 00 and 1-36).
  30.             Set counter equal to 0.
  31.         WHILE counter is less than 4 increment counter.            
  32.                IF bet number is equal to random winning pocket.
  33.           THEN
  34.                      Display bet number.
  35.                      Display bet amount.
  36.                      Display winning number.
  37.                      Calculate payout using the formula payout = bet amount multiplied by 36 .
  38.                      Display payout.
  39.                      Add payout onto subtotal profit/loss.
  40.                      Display subtotal profit/loss.
  41.                END IF
  42.          ELSE
  43.                   THEN
  44.                      Display bet number.
  45.                      Display bet amount.
  46.                      Display winning number.
  47.                      Subtract bet amount from subtotal profit/loss.
  48.                      Display payout = 0.
  49.                      Display subtotal profit/loss.
  50.                END ELSE
  51.             END WHILE
  52.       END ELSE
  53.    Display total profit/loss.
  54. */
  55.  
  56. #include <stdio.h>
  57. #include <time.h>
  58. #include <string.h>
  59.  
  60.  
  61. int main (void)
  62. {
  63.    int amountwon=0;
  64.    int total;
  65.    int j=0;
  66.    int subtotal=0;
  67.    int rndnumber;
  68.    int loop= 0;
  69.    int error= 0;
  70.    int word, inputposition, amountposition;
  71.    int validinput[4] = {-1, -1, -1, -1}; /*Array is populated with -1 values to meet requirements for future error checking processes for each character in the bet number string*/
  72.    char amountbet[4][11]; /*Character length must be greater than input character to avoid errors due to end of line characters.*/
  73.    char inputnum[4][4]; /*Character length must be greater than input character to avoid errors due to end of line characters.*/
  74.    char validnum[37][4]; /*Character length must be greater than input character to avoid errors dues to end of line characters.*/
  75.    
  76.    for( word =0; word <4; word ++ ) /*For loop will loop 4 times to allow for population of the strings.*/
  77.       {
  78.       for( inputposition =0; inputposition <4; inputposition ++ )
  79.          {
  80.          inputnum[word][inputposition] = '\0'; /*Bet number string and characters are populated with null characters to avoid errors in later code*/
  81.          }
  82.      
  83.       for( amountposition =0; amountposition <11; amountposition ++ )
  84.          {
  85.          amountbet[word][amountposition] = '\0'; /*Bet amount string and characters are populated with null characters to avoid errors in later code*/
  86.          }
  87.       }
  88.  
  89.    scanf( "%s %s %s %s %s %s %s %s", inputnum[0], amountbet[0], inputnum[1], amountbet[1], inputnum[2], amountbet[2], inputnum[3], amountbet[3]); /*Input values are assinged as string characters to the bet number and bet amount strings which allows the input of the "00" value*/
  90.    
  91.    for( loop = 0; loop < 37; loop++ ) /*For loop will loop 36 times to create a string of valid input values*/
  92.       {
  93.       sprintf( validnum[loop],"%d",loop ); /*Assigns the decimal loop value to its corresponding valid input number in the string valid input number string from 0 to 36*/
  94.       }
  95.       sprintf( validnum[37],"00" ); /*Assigns the character 00 to the 37th valid input number position in the string valid input number string.*/
  96.          
  97.    for( j = 0; j < 4; j++ ) /*Creates a for loop that will loop 4 times to allow future error testing of the 4 input bet numbers and bet amounts*/
  98.       {
  99.       for( loop=0; loop<38; loop++ ) /*For loop that will loop 4 times to allow future comparison error testing of the 38 valid input numbers*/ 
  100.            {
  101.        if ( strcmp( inputnum[j], validnum[loop]) == 0 ) /*Checks to see if the input bet numbers contained in the input bet string are found in the string of valid bet numbers*/
  102.             {
  103.             validinput[j] = loop; /*Sets the string position of the valid input string to the value of the loop which makes it no longer equal to -1*/
  104.             break; /*Breaks out of the current for loop that loops 38 times.*/
  105.             }
  106.          }
  107.        if (validinput[j] == -1) /*Checks to see if the valid input string characters are still equal to -1*/
  108.            {
  109.             error = 1; /*Error indicator is turned on.*/
  110.             break; /*Breaks out of the current for loop as an error criteria has been met.*/
  111.             } 
  112.       for ( loop = 0; loop < strlen(amountbet[j]); loop++ ) /*For loop that will loop until it reaches the value that is 1 less than the length of the character j in the bet amount string.*/
  113.          {
  114.          if (isdigit(amountbet[j][loop]) == 0) /*Checks to find any characters in the amount bet string that are not digits*/
  115.             {
  116.             error = 1; /*Error indicator is turned on.*/
  117.             break; /*Breaks out of the current for loop as an error criteria has been met.*/
  118.             }
  119.          if ((atoi( amountbet[j] ) < 1))  /*Checks to find any characters in the amount bet string that are digits that are less than 1.*/
  120.             {
  121.             error = 1; /*Error indicator is turned on.*/
  122.             break; /*Breaks out of the current for loop as an error criteria has been met.*/
  123.             }
  124.          if ((atoi( amountbet[j] ) > 1000000000))  /*Checks to find any characters in the amount bet string that are digits with value greater than 1 billio.*/
  125.             {
  126.             error = 1; /*Error indicator is turned on.*/
  127.             break; /*Breaks out of the current for loop as an error criteria has been met.*/
  128.             }
  129.          }
  130.     }
  131.      
  132.    if (error == 1) /*If the error indicator is turned on the error sequence will run.*/
  133.       {
  134.       printf ("\nerror:\
  135.       \nPlease input 4 pairs of valid bet numbers and bet amounts.\
  136.       \nThe valid input numbers and bet amounts must be positive integers.\
  137.       \nThe possible valid bet numbers are 00 and 0 to 36.\
  138.       \nBet amounts must be no less than 1 and no greater than 1,000,000,000.\
  139.       \nInputs must be free of punctuation marks."); /*Displays message regarding all possible errors that may have occured.*/
  140.       }
  141.      
  142.    else /*If the error indicator is turned off the calculation sequences will run.*/
  143.       {
  144.       srand( time(0) ); /*Set the seed for the random number generator to the current time*/
  145.       rndnumber = rand() % 38; /*Sets the random number variable to be equal to the random number generated within the range of 0 and 37*/
  146.       for ( j = 0; j < 4; j++) /* For loop that will loop 4 times.*/
  147.          {
  148.        if (validinput[j] == rndnumber) /*When the valid input character j in the valid input string is equal to the value of the random number variable the win scenario will run.*/
  149.            {
  150.         amountwon = 36 * atoi(amountbet[j]); /*The amount won variable is calculated as 36 mulitplied by the inputted decimal value of the character j in the amount bet string.*/
  151.         subtotal += amountwon; /*The subtotal value is calculated to equal itself plus the value of the amount won variable.*/
  152.         printf("\nBet number %d is %s\
  153.             \nAmount bet on bet number %d is %d\
  154.             \nThe winning number is %s\
  155.             \nYour payout is %d\
  156.             \nYour subtotal profit/loss is %d", (j + 1), inputnum[j], (j + 1), atoi(amountbet[j]), validnum[rndnumber], amountwon, subtotal );
  157.            } /*Displays the jth bet number, the jth bet amount, The winning number, the calculated payout on the jth bet and the subtotal profit/loss from the jth bet.*/
  158.            
  159.        else
  160.            {
  161.         amountwon = -atoi(amountbet[j]); /*The amount won variable is calculated as the negative of inputted decimal value of the character j in the amount bet string.*/
  162.         subtotal += amountwon; /*The subtotal value is calculated to equal itself plus the value of the amount won variable.*/
  163.         printf("\nBet number %d is %s\
  164.             \nAmount bet on bet number %d is %d\
  165.             \nThe winning number is %s\
  166.             \nYour payout is 0\
  167.             \nYour subtotal profit/loss is %d", (j + 1), inputnum[j], (j + 1), atoi(amountbet[j]), validnum[rndnumber], subtotal );
  168.            } /*Displays the jth bet number, the jth bet amount, The winning number, that payout on the jth bet is 0 and the subtotal profit/loss from the jth bet.*/
  169.          }
  170.          
  171.       total = subtotal; /*The total profit/loss is set equal to the final subtotal variable after the 4 bet calulations have finished.*/
  172.       printf("\nYour total profit/loss is %d", total); /*Displays the total profit/loss.*/
  173.       }
  174.      
  175.    return (0); /*Returns a value to the compiler to show that the program has ended to avoid compiling errors.*/
  176. }