<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. Psuedo Code
  3.  
  4. START
  5.    Read inputs
  6.       WHILE reading input numbers
  7.          Set a counter for 8 counts
  8.          IF input number is divided by 2 and has a reminder
  9.             THEN
  10.                Store the bet amount
  11.          ELSE
  12.            Store the bet number
  13.             Display informative error messages regarding legitimacy of inputs of bet number
  14.          END IF   
  15.       END WHILE
  16.    Spin Wheel with numbers from 0 to 37 (37 equalling 00)
  17.    Display winning number
  18.       WHILE Comparing bet numbers against winning number
  19.          Set a counter for the amount of bets placed     
  20.          IF Bet Number is equal to winning number
  21.             THEN
  22.                 Multiply Bet Amount by 35
  23.                 Display message for win
  24.                 Display current win/loss total
  25.                
  26.          ELSE Take away bet amount from players wallet
  27.                Display message for loss
  28.                Display current Win/Loss total
  29.       END WHILE     
  30.    Display Total Winnings or Loss of all four bets
  31. END
  32. */
  33.  
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <time.h>
  37. #include <string.h>
  38. #include <ctype.h>
  39.  
  40. int errorcheck(   char[]   ); /* setup of created function */
  41.  
  42. int main(   void  )
  43. {
  44. srand( time( 0 ) ); /* timer setup */
  45. int Random = rand()%38; /* randomiser to chose a number between 0 and 37 */
  46. int count = 0;
  47. float sum = 0;
  48. int i;
  49. int Bets[4] = {0}; /* used for converting from askii characters to integers */
  50. char DoubleZero[2] = {"00"}; /* 00 string to be used to compare against bet number */
  51. char BetNumber1[2] = {"\0"}; /* individual arrays for each bet number */
  52. char BetNumber2[2] = {"\0"};
  53. char BetNumber3[2] = {"\0"};
  54. char BetNumber4[2] = {"\0"};
  55. float BetAmount[4]= {0}; /* all bet amounts go here */
  56.  
  57.                                /* #### Sorting of the inputs #### */
  58.                                
  59. for(i=1; i<9; i++){ /* FOR loop to seperate floats and strings */
  60.    if( i%2==0) /* modulus used to filter inputs */
  61.    {
  62.       scanf("%f",&BetAmount[count]); /* places floats within the BetAmount array regarding the count number */
  63.       count+=1;
  64.    }
  65.    else
  66.    {
  67.    
  68.       switch(i){ /* places each bet number into a seperate array and error check whilst doing this */
  69.          case 1: scanf("%s",BetNumber1);
  70.                   if(errorcheck(BetNumber1)) /* error check BetNumber */
  71.                   return 0; /* runs if error check returns a 0 */
  72.                   break;
  73. /* same as above for remaining switch statements */                 
  74.          case 3: scanf("%s",BetNumber2);
  75.                   if(errorcheck(BetNumber2))
  76.                   return 0;
  77.                   break;
  78.                  
  79.          case 5: scanf("%s",BetNumber3);
  80.                   if(errorcheck(BetNumber3))
  81.                   return 0;
  82.                   break;
  83.                  
  84.          case 7: scanf("%s",BetNumber4);
  85.                   if(errorcheck(BetNumber4))
  86.                   return 0;
  87.             break;
  88.   }             
  89.  }
  90. }
  91.  
  92.                                  /* #### Conversion of Bet Number Array #### */
  93.  
  94. Bets[0] = atoi(BetNumber1); /* conversion from askii character to integer */
  95. Bets[1] = atoi(BetNumber2); /* stored as intergers in Bets array */
  96. Bets[2] = atoi(BetNumber3);
  97. Bets[3] = atoi(BetNumber4);
  98.  
  99.                                  /*#### Random Number generator #### */
  100.  
  101. if( Random == 37 ) printf("The Winning number is 00\n\n"); /* IF statement to produce 00 as a legitimate bet number */
  102. else printf("The Winning number is %d\n\n", Random);
  103.  
  104.                                  /* #### Calculating Winning number, Conversion rates, outputs #### */
  105.                                  
  106. for(i=0; i<4; i++){
  107. /* use of  switch statements for easier micro managing of individual arrays and bet outcomes */
  108.  switch (i){
  109.  
  110.    case 0:
  111.       if(!strcmp(BetNumber1,DoubleZero) && Random == 37){ /* compares BetNumber 1 to DoubleZero if equal to 00 */
  112.          sum += BetAmount[i]*35; /* winning rates */
  113.          printf("The player placed a bet on 00 and placed a bet amount of %5.2f\nThe player wins %5.2f\n", BetAmount[i], BetAmount[i]*35);
  114.          }
  115.       else if (Bets[i] == Random){ /* if winning number not equal to 00, follow through with this statement for potential other win scenario */
  116.          sum += BetAmount[i]*35; /* winning rate */
  117.          printf("The player placed a bet on %d and placed a bet amount of %5.2f\nThe player wins %5.2f\n",Bets[i], BetAmount[i], BetAmount[i]*35);
  118.          }
  119.       else{
  120.          sum -= BetAmount[i]; /* losing scenario, deduct following for from sum */
  121.          printf("The player placed a bet on %s and placed a bet amount of %5.2f\nBetter luck next time, you lost -%5.2f\n",BetNumber1, BetAmount[i], BetAmount[i]);
  122.      }
  123.       printf("Current Win/Loss total is %5.2f\n\n",sum);
  124.       break; /* break here once BetNumber1 is complete and move onto next case */
  125.  
  126. /* switch statements beneathe have the same function as case above just aimed at the three remaining BetNumber arrays */
  127.    case 1:
  128.       if(!strcmp(BetNumber2,DoubleZero) && Random == 37){
  129.          sum += BetAmount[i]*35;
  130.          printf("The player placed a bet on 00 and placed a bet amount of %5.2f\nThe player wins %5.2f\n", BetAmount[i], BetAmount[i]*35);
  131.      }                                   
  132.       else if (Bets[i] == Random){
  133.          sum += BetAmount[i]*35;
  134.          printf("The player placed a bet on %d and placed a bet amount of %5.2f\nThe player wins %5.2f\n",Bets[i], BetAmount[i], BetAmount[i]*35);
  135.      }
  136.       else{
  137.          sum -= BetAmount[i];
  138.          printf("The player placed a bet on %s and placed a bet amount of %5.2f\nBetter luck next time, you lost -%5.2f\n",BetNumber2, BetAmount[i], BetAmount[i]);
  139.      }
  140.       printf("Current Win/Loss total is %5.2f\n\n",sum);
  141.       break;
  142.      
  143.    case 2:
  144.       if(!strcmp(BetNumber3,DoubleZero) && Random == 37){
  145.          sum += BetAmount[i]*35;
  146.          printf("The player placed a bet on 00 and placed a bet amount of %5.2f\nThe player wins %5.2f\n", BetAmount[i], BetAmount[i]*35);
  147.      }                                 
  148.       else if (Bets[i] == Random){
  149.          sum += BetAmount[i]*35;
  150.          printf("The player placed a bet on %d and placed a bet amount of %5.2f\nThe player wins %5.2f\n",Bets[i], BetAmount[i], BetAmount[i]*35);
  151.      }
  152.       else{
  153.          sum -= BetAmount[i];
  154.          printf("The player placed a bet on %s and placed a bet amount of %5.2f\nBetter luck next time, you lost -%5.2f\n",BetNumber3, BetAmount[i], BetAmount[i]);
  155.      }
  156.       printf("Current Win/Loss total is %5.2f\n\n",sum);
  157.       break;
  158.      
  159.    case 3:
  160.       if(!strcmp(BetNumber4,DoubleZero) && Random == 37){
  161.          sum += BetAmount[i]*35;
  162.          printf("The player placed a bet on 00 and placed a bet amount of %5.2f\nThe player wins %5.2f\n", BetAmount[i], BetAmount[i]*35);
  163.       }                               
  164.       else if (Bets[i] == Random){
  165.          sum += BetAmount[i]*35;
  166.          printf("The player placed a bet on %d and placed a bet amount of %5.2f\nThe player wins %5.2f\n",Bets[i], BetAmount[i], BetAmount[i]*35);
  167.       }
  168.       else{
  169.          sum -= BetAmount[i];
  170.          printf("The player placed a bet on %s and placed a bet amount of %5.2f\nBetter luck next time, you lost -%5.2f\n",BetNumber4, BetAmount[i], BetAmount[i]);
  171.       }
  172.       printf("Current Win/Loss total is %5.2f\n\n",sum);
  173.       break;
  174.      
  175.    default: return 45; /* Return error code 45 in the event of system critical error*/
  176.   }
  177.  }
  178.  
  179.                            /* #### Summary of Winnings/Losses #### */
  180.  
  181. /* added three ending soultions for the chance of breaking even hence if statement */
  182. if(sum==0) printf("\nYou have broken even");
  183. else if(sum >0) printf("\nCongratulations, you have won a total of %5.2f",sum);
  184. else printf("\nBetter luck next time, you have lost a total of %5.2f",sum)
  185. }
  186.  
  187.  
  188.                            /* #### External errorcheck function for BetNumber ##### */
  189.                            
  190. int errorcheck(char* BetNumber){ /* pointer location for BetNumber array */
  191.    int i = 0;
  192.    
  193.    for(i=0; i<2; i++){
  194.       if( isspace(BetNumber[i]) ){ /* stops blanks spaces being inputted as bet numbers */
  195.          printf("Please check your inputs (No blank spaces to be entered)");
  196.          return 1; /* return 1 if this statement is true and produce following error message */
  197.          }
  198.       if( isalpha(BetNumber[i]) ){ /* stops letters being inputted on a bet number  */
  199.          printf("Please enter a valid bet (No letters/Words)");
  200.          return 1;
  201.          }
  202.       if( ispunct(BetNumber[i]) ){
  203.          if( BetNumber[i]=='-'){ /* stops negative bet numbers */
  204.             printf("Please enter a positive number");
  205.             return 1;
  206.             }
  207.            
  208.          if( BetNumber[i]=='.'){ /* stops invalid numbers being inputted */
  209.             printf("Please enter a valid bet number (No Decimals)");
  210.             return 1;
  211.             }
  212.          else{
  213.             printf("Please enter a valid bet (No Punctutation)")/* stops punctuation being added to bet number */
  214.             return 1;
  215.          }
  216.          }
  217.    
  218.      
  219.      }
  220.    return 0; /* if BetNumber Arrays to not meet any of the above then they are valid inputs */
  221. }