<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. START
  3.   Obtain bet numbers
  4.   Obtain bet amounts
  5.   Set all valid inputs in array -1
  6.   Display bet numbers and how much on each number
  7.   IF all amounts bet are greater than 0
  8.     IF all numbers to bet on are greater than -1
  9.          Set valid bets 0-37
  10.      Set number 37 to "00"
  11.          Check bet inputs against valid bets array to check validity
  12.             IF valid
  13.                Store bet in valid array
  14.             END IF
  15.      
  16.             Compare input bets numbers to the randomly generated number
  17.             IF bet matches random number
  18.                Mulitply betvalue by 35, add value to winnings
  19.                Add winnings to subtotal
  20.             ELSE
  21.                Minus bet value from the subtotal
  22.             END IF
  23.                  
  24.         IF valid = -1
  25.                Display error message for invalid bet
  26.             ELSE
  27.                IF win
  28.                   Display winning message, payout, new balance
  29.                ELSE
  30.                   display loss message, new balance
  31.                END IF
  32.             END IF      
  33.       ELSE
  34.          Display error message for bet numbers less than 0 are invalid
  35.       END IF
  36.      
  37.   ELSE
  38.      Display error message for bet values and state that bet has to be greater that 1
  39.   END IF
  40.  
  41. END
  42. */
  43.  
  44. #include <stdio.h>            
  45. #include <time.h>
  46. #include <string.h>
  47. #include <stdlib.h>
  48.  
  49. int main(void)
  50. {
  51.    char betvalue[4][12];                  /*create array with 4 integers, with a potential for large amounts
  52.                  - done so even large monetary value can be entered without causeing problems to the program*/
  53.    int winnings = 0;        /* create winnings variable and initialise as 0 */
  54.    int subtotal =0;                /* create subtotal variable and initialise as 0 */
  55.    char bet[4][4];                        /* create array with 4 numbers and 4 digits each as to avoid errors caused by the end of line characters*/
  56.    char possbet[38][4];       /* create array for the 38 possible bets, and 4 deep to avoid the end of line errors */
  57.    int random;          /* create random variable */
  58.    int valid[4] = {-1,-1,-1,-1};    /* create array for valid number checking, and set to values of -1 each for future error checking*/
  59.    int error =0;                  /* initialise error value as 0*/
  60.    int i;
  61.  
  62.    scanf("%s %s %s %s %s %s %s %s", bet[0], &betvalue[0], bet[1], &betvalue[1], bet[2], &betvalue[2], bet[3], &betvalue[3]);
  63.    
  64.    printf("You've bet %s on number %s, %s on number %s, %s on number %s, and %s on number %s", &betvalue[0], bet[0], &betvalue[1], bet[1], &betvalue[2], bet[2], &betvalue[3], bet[3]);
  65.  
  66.     if ((atoi(betvalue[0]) >0) && (atoi(betvalue[1]) > 0) && (atoi(betvalue[2]) > 0) && (atoi(betvalue[3]) > 0)) {             /* bet values have to be more than 0, as you cannot bet 0 */       
  67.      
  68.       if ((atoi(bet[0]) > -1) && (atoi(bet[1]) > -1) && (atoi(bet[2]) > -1) && (atoi(bet[3]) > -1)){                      /* bet values have to be greater than 0 */
  69.    
  70.       for (int a=0; a<37; a++) {          /* loop through number starting at 0 and finishing at 37 */
  71.    
  72.       sprintf( possbet[a], "%d", a);                        /* sets 36 possible bets and adds them to array possbet[a] */
  73.       sprintf( possbet[37], "00");                  /* sets 37 in possbet[a] to '00' allowing program to read 00 seperately from 0 */
  74.      
  75.       }
  76.    
  77.     for (int i=0; i<4; i++){          /* scanning variable i for greater than 0, less than 4 and incrementing at each loop */
  78.      
  79.       for (int j=0; j<38; j++){                    /* for when variables are valid, scan then increment */
  80.          
  81.          if (strcmp(bet[i], possbet[j]) ==0){               /* checking the input values are in the valid bet range */
  82.                valid[i] = j;
  83.                }
  84.          }
  85.          if (valid[i] == -1){           /* if valid aray still contains an invalid number then display error message */
  86.             printf("\n\nOnly whole numbers between 00 and 36 are valid. Please enter a valid number you would like to bet on.");                                    
  87.               break;              /* if error is found exit loop */
  88.               }
  89.                  
  90.          
  91.          else
  92.          {
  93.          srand( time(0));                                    /* relate random number to time */
  94.           random = rand()%38;           /* set random number to only vary between 0 and 37(for 00) */
  95.          
  96.             if(valid[i]== random){                    /* check to seeif win conditions are met */
  97.             
  98.                winnings = 36 * atoi(betvalue[i]);          /* payout is 35 times original bet, plus original bet. atio changes string character back to origianl value */
  99.                subtotal += winnings;                           /* updates subtotal with winnings */
  100.                }
  101.          
  102.             else{
  103.             subtotal -= atoi(betvalue[i]);                  /* because loss, remove the bet value from subtotal. atio gives original numerical value to calculation */
  104.             }
  105.             if (valid[i] == random)         /* check for win conditions */
  106.             {
  107.                printf("\n\nWinning number is %d.\nYou win!\nYour return is %d.\nAfter taking your lots bets, Your new wallet balance is %d.", random, winnings, subtotal);          /*display winning message */
  108.                }
  109.             else
  110.             {
  111.                printf("\n\nwinning number is %d.\nYou lose\nYou lose you bets\nYour new wallet balance is %d.", random, subtotal);      /* display losing message */
  112.                }
  113.                }
  114.                }
  115.          printf("\n\nYour total profit/loss for this round is %d", subtotal);                  /* display over all profit and loss total */
  116.          }
  117.          
  118.       else {
  119.             printf("\n\nOnly whole numbers between 00 and 36 are valid. Please enter a valid number you would like to bet on.");             /* program error messages for termination from original If statements */   
  120.          } 
  121.          }
  122.       else{   
  123.          printf("\n\nAny bets less that 1 are not valid. please enter whole number bets greater than 1.");       /* program error messages for termination from original If statements */ 
  124. }
  125. }