<mosaic.cnfolio.com>
PROGRAM
  1. /* PSEUDO CODE ---- PSEUDO CODE ---- PSEUDO CODE ---- PSEUDO CODE ---- PSEUDO CODE ---- PSEUDO CODE ---- PSEUDO CODE ----
  2.  
  3. START PROGRAM
  4.  
  5. MAIN FUNC
  6. START MAIN
  7.  
  8. CHAR BetString[2]
  9. BOOL IsValid = false
  10. INT 2DBetArray[4][2]
  11. INT RandomNum
  12. INT Balance
  13. INT StringInputCompare
  14. INT ReadNum
  15.  
  16. INT count
  17.  
  18. FOR count < 4
  19.    INPUT user enters 4 pairs of number that represent the bets
  20.    STORE input in 2DBetArray[count][0], 2DBetArray[count][1]
  21.    IF INPUT < 4 Bets
  22.       PRINT 'Error'
  23.       EXIT
  24.    END IF
  25.    
  26.    CHAR C = BetString
  27.    IF C = '-'
  28.       IsValid = True
  29.    END IF
  30.    DO WHILE
  31.       IsValid = False
  32.       IF NotDigit (C)
  33.          IsValid = True
  34.          Break
  35.       END IF
  36.       Increment C to next letter
  37.    END DO
  38.    WHILE C != '\0' AND C != '\n'
  39.    
  40.    IF IsValid = True
  41.       PRINT 'ERROR'
  42.       EXIT
  43.      
  44.    END IF
  45.    
  46.    DoubleZero = '00'
  47.    StringInputCompare = STRING COMPARE BetStr, DoubleZero
  48.    
  49.    IF StringInputCompare != 0
  50.       2DBetArray[count][0] = CONVERTtoINT(BetString)
  51.       IF 2DBetArray[count][0] < 0 OR 2DBetArray[count][0] > 37
  52.          PRINT 'ERROR'
  53.          EXIT
  54.       ELSE
  55.          IF 2DBetArray[count][1] < 0 OR 2DBetArray[count][1] > 10000
  56.             PRINT 'Error'
  57.             EXIT
  58.          END IF
  59.       END IF
  60.    ELSE IF StringInputCompare == 0
  61.       2DBetArray[count][0] = 37
  62.       IF 2DBetArray[count][1] < 0 OR 2DBetArray[count][1] > 10000
  63.          PRINT 'ERROR'
  64.          EXIT
  65.       END IF
  66.    ELSE
  67.       PRINT 'ERROR'
  68.       EXIT
  69.    END IF   
  70. END FOR
  71.  
  72. count = 0
  73. FOR count < 4
  74.    RandomNum = RandomNumberGenerator
  75.    IF RandomNum = 2DBetArray[count][0](Bet Number)
  76.       PRINT 'YOU WON'
  77.       PRINT 'Your Number: 2DBetArray[count][0]'
  78.       PRINT 'Your Bet Amount: 2DBetArrayt[count][1]'
  79.       PRINT 'Wheel Number: RandomNum'
  80.       PRINT 'Your Winnings: 2DBetArray[count][1] X 35'
  81.    ELSE
  82.       PRINT 'YOU LOSE'
  83.       PRINT 'Your Number: 2DBetArray[count][0]'
  84.       PRINT 'Your Bet Amount: 2DBetArrayt[count][1]'
  85.       PRINT 'Wheel Number: RandomNum'
  86.       PRINT 'Your Loses: 2DBetArray[count][1]'
  87.    END IF
  88. END FOR
  89.    PSEUDO CODE ---- PSEUDO CODE ---- PSEUDO CODE ---- PSEUDO CODE ---- PSEUDO CODE ---- PSEUDO CODE ---- PSEUDO CODE ----
  90. */
  91.  
  92. #include <stdio.h>
  93. #include <stdlib.h>
  94. #include <string.h>
  95. #include <time.h>
  96. #include <stdbool.h>
  97. #include <ctype.h>
  98.  
  99. /*Fucntion Prototype Declaration to allocate memory*/
  100. int results(int *b);
  101.  
  102. int main (void)
  103. {
  104.    
  105.    char betStr[2];      /* Character array to store input, Using Character array to accept double zero input */
  106.    int isValid = 0;    /* Integer value to act a boolean value for error checking logic below */
  107.    char doubZero[2];  /* A character varaible to store double zero string for comparison, as character arrays cannot be compared using assignment */
  108.    int betVar[4][2];  /* 2 Dimensional Integer array to store Bet Number and amount */
  109.    int balance = 0;    /* Integer to store the accumalative balance */
  110.    int randomNum;   /* Integer to store the number generated by the machine */
  111.    int strInCmp;      /* An integer to store the return value from the String Compare function */
  112.    int readNum = 0;    /* An integet to store the number of inputs read by the scanf function */
  113.    
  114.    
  115.    printf("Your Bets:\n");
  116.    
  117.    int i = 0;
  118.    /* A loop to read the 4 pairs of bets */
  119.    for (i; i < 4; i++)
  120.    {
  121.       /* scanf statement to read a string and decimal value */
  122.       readNum = scanf("%s %d\n", &betStr, &betVar[i][1]);
  123.       /* When the compiler doesn't detect a complete bet pair, an error is shown and program exits */
  124.       if (readNum != 2)
  125.       {
  126.          printf("Please enter 4 bets in the format [Bet Number][Bet Amount]");
  127.          exit(0);
  128.       }
  129.       /* Assign the character string to a pointer character string to validate the string */
  130.       char *c = betStr;
  131.       /* Prevents input of negative numbers */
  132.       if (*c == '-')
  133.       {
  134.          isValid = 1;
  135.       }
  136.       /* Do While loop to step through the character string */
  137.       do
  138.       {
  139.          isValid = 0;
  140.          /* If there are no decimal values, show error, program exit */
  141.          if (!isdigit(*c))
  142.          {
  143.             isValid = 1;
  144.             break;
  145.          }
  146.          /* Increment to the next character */
  147.          ++c;
  148.         /* Do until null charater is reached */
  149.       } while (*c != '\0' && *c != '\n');
  150.       /* if statement containing error message if an exception is thrown above */
  151.       if (isValid == 1)
  152.       {
  153.          printf("Invalid input! Please enter a bet between 00 and 36!");
  154.          exit(0);
  155.       }
  156.       /* assigns DoubleZero to string 00 */
  157.       strcpy(doubZero, "00");
  158.       /*if betStr is the same as 00 return 0. If not return 1. */
  159.       strInCmp = strcmp(betStr, doubZero);
  160.      
  161.       /*proof of development https://codepad.remoteinterview.io/VQQKOAKNBK */
  162.       /* If the strings do not match run below code contained */
  163.       if (strInCmp != 0)
  164.       {
  165.          /* Assign the array the converted integer using atoi function (I know, not the most robust solution) */
  166.          betVar[i][0] = atoi(betStr);
  167.          /* if the value is out of the accepted bounds present error and exit */
  168.          if (betVar[i][0] < 0 || betVar[i][0] > 36)
  169.          {
  170.             printf("Error Code 1: Invalid Bet Number on Bet %d! Please enter a number from 00 to 36!", i + 1);
  171.             exit(0);           
  172.            
  173.          }
  174.          else
  175.          {
  176.             /* if the value is out of the accepted bounds present error and exit */
  177.             if (betVar[i][1] < 0 || betVar[i][1] > 10000)
  178.             {
  179.                printf("Error Code 3: Invalid Bet Amount on Bet %d! Please enter an amount between 1 and 10000!", i + 1);
  180.                exit(0);
  181.             }
  182.          }
  183.       }
  184.       /* if the two strings match, assign the array to 37 in place of 00 */
  185.       else if (strInCmp == 0)
  186.       {
  187.          betVar[i][0] = 37;
  188.          /* if the value is out of the accepted bounds present error and exit */
  189.          if (betVar[i][1] < 0 || betVar[i][1] > 10000)
  190.          {
  191.             printf("Error Code 3: Invalid Bet Amount on Bet %d! Please enter an amount between 1 and 10000!", i + 1);
  192.             exit(0);
  193.          }
  194.       }
  195.       /* if there is any other error with comaprison e.g. incorrect type conversion, show error and exit */
  196.       else
  197.       {
  198.          printf("Error Code 2: Invalid Bet Number on Bet %d! Please enter a number from 00 to 36!", i + 1);
  199.          exit(0);
  200.       }
  201.    }
  202.    
  203.    printf("------------------------------------------------\n");
  204.    /* Seeds the RNG */
  205.    srand(time(NULL));
  206.    /* Loop for displaying output for the 4 bets */
  207.    for (i = 0; i < 4; i++)
  208.    {
  209.       /* Generate random number in a range between 0 and 37  */
  210.       randomNum = rand() % 38;
  211.       if(randomNum == betVar[i][0])
  212.       {
  213.          /* add to balance the bet ammount multiplied by the odds */
  214.          balance += (betVar[i][1] * 35);
  215.          printf("You Won!\n");
  216.          /* if the bet number equals 37, display 00 to the console */
  217.          if (betVar[i][0] == 37)
  218.          {
  219.             printf("Your Number: 00\n");
  220.          }
  221.          /* else display the value stored in the array */
  222.          else
  223.             printf("Your Number: %d\n", betVar[i][0]);
  224.            
  225.          printf("Your Bet Amount: %d\n", betVar[i][1]);
  226.          /* if RNG number is 37 display 00 */
  227.          if (randomNum == 37)
  228.             printf("Wheel Number: 00\n");
  229.          else
  230.          printf("Wheel Number: %d\n", randomNum);
  231.          
  232.          printf("Total Bet Payout: %d\n", betVar[i][1] * 35);
  233.          printf("Winnings/Loses: %d\n", (betVar[i][1] * 35) + betVar[i][1]);
  234.          printf("------------------------------------------------\n");
  235.       }
  236.       else
  237.       {
  238.          /* deduct amount bet from balance */
  239.          balance -= betVar[i][1];
  240.          printf("You Lose!\n");
  241.          if (betVar[i][0] == 37)
  242.          {
  243.             printf("Your Number: 00\n");
  244.          }
  245.          else
  246.             printf("Your Number: %d\n", betVar[i][0]);
  247.            
  248.          printf("Your Bet Amount: %d\n", betVar[i][1]);
  249.          if (randomNum == 37)
  250.             printf("Wheel Number: 00\n");
  251.          else
  252.          printf("Wheel Number: %d\n", randomNum);
  253.          
  254.          printf("Total Bet Payout: -%d\n", betVar[i][1]);
  255.          printf("Winnings/Loses: -%d\n", betVar[i][1] );
  256.          printf("------------------------------------------------\n");
  257.       }
  258.    }
  259.    /* call results function passing balance varibale */
  260.    results(&balance);
  261. }
  262.  
  263. int results(int *b)
  264. {
  265.    /* if balance is positive, display it as winnings */
  266.    if (*b > 0)
  267.    printf("Total Winnings: %d\n", *b);
  268.    /* if balance is negative, display it as loses */
  269.    else
  270.    printf("Total Loses: %d\n", *b);
  271. }