<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. START
  3.    Populate a database with all the possible bet names, numbers and odds
  4.    Recieve the users bets via an input
  5.    Generate a random number and get the modulus of it with 38
  6.    WHILE there are bets left
  7.       check if the bet is in the list
  8.       IF the bet is in the database
  9.          THEN there is no error with the input
  10.     ELSE
  11.               there is an error with the input so display that there is an error
  12.       END IF
  13.    END WHILE
  14.    WHILE there are bets left
  15.       IF the bet is the same as the result of the spin
  16.          THEN they win and therefore winnings = bet x odds
  17.       ELSE they lose and winnings = winnings - bet
  18.       END IF
  19.       Display the net profit for that bet and the subtotal as of that bet
  20.    END WHILE
  21.    Display the total net profit from all 4 bets
  22. END
  23. */
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <time.h>
  27. #include <stdlib.h>
  28. struct Database{
  29.       char  BetName[4] ;
  30.       int   Odds;
  31. }    Betinfo[38];
  32.  
  33.  
  34. void LoadBetInfo (void);
  35.  
  36. int main( void ){
  37.    int spinresult =0 , beterror[4] = {0}, winnings[4] ={0}, subtotal=0, moneyerror[4]={0};
  38.    float money[4]={0};
  39.    char bet[4][4] , moneystr[4][4];
  40.    
  41.    for(int t=0;t<4;t++){
  42.       for(int y=0;y<4;y++){
  43.          bet[t][y] ='\0';
  44.          moneystr[t][y] = '\0';
  45.          }
  46.       }
  47.      
  48.    LoadBetInfo();
  49.    scanf("%s %s %s %s %s %s %s %s", bet[0], moneystr[0], bet[1], moneystr[1], bet[2], moneystr[2], bet[3], moneystr[3]);
  50.    
  51.    for (int l=0;l<4;l++){
  52.    money[l] = atof(moneystr[l]);
  53.    }
  54.    
  55.    
  56.    for(int j = 0; j<4; j++){
  57.       for(int k = 0; k<38; k++)
  58.       {
  59.           if (strcmp(Betinfo[k].BetName, bet[j])!=0){ /* runs through the database to check if the input is a valid bet*/
  60.             beterror[j]= 1;
  61.             }
  62.           else{
  63.             beterror[j] = 0;
  64.             break;
  65.       }
  66.       }
  67.          if ((money[j] <1) || (floor(money[j]) != money[j])){ /* checks if the users money input is a positive integer*/
  68.             moneyerror[j]=1;
  69.          }
  70.          else{
  71.             moneyerror[j]=0;
  72.        }
  73.    }
  74.    
  75.    srand(time( 0 ))
  76.    spinresult = rand() %38; /* generates the wheel spin*/
  77.    
  78.    
  79.    for(int i=0;i<4;i++){
  80.       if((beterror[i]==0) && (moneyerror[i]==0)){
  81.          if (strcmp(Betinfo[spinresult].BetName,bet[i])==0)
  82.          {
  83.             winnings[i] = (money[i] * Betinfo[spinresult].Odds); /* calculates how much the user has won*/
  84.          }
  85.          else{
  86.             winnings[i] = (winnings[i] - money[i]); /* calculates how much the user has lost*/
  87.          }
  88.           subtotal += winnings[i];
  89.             printf("\nYou bet %.0f on %s, the winning number was %s, your net profit this bet was %d and your subtotal is %d", money[i], bet[i], Betinfo[spinresult].BetName, winnings[i], subtotal);
  90.     }
  91.       else{
  92.           if (beterror[i]==1) printf("\nThat bet does not exist, please try again"); /* tells the user that the input was wrong*/
  93.      
  94.           else  printf("\nThere was an error with your bet, please make sure it was an integer greater than 0");
  95.          }
  96. } 
  97.    
  98. printf("\nYour total profit was %d", subtotal); /* Displays the total profit */
  99. }
  100.  
  101.  
  102. void  LoadBetInfo   (void){ /* fills the database with all the possible single number bets and their odds*/
  103.    for (int count=0;count<37;count++){
  104.       sprintf(Betinfo[count].BetName, "%d", count);
  105.       Betinfo[count].Odds = 35;
  106.    }
  107.    sprintf(Betinfo[37].BetName, "00");
  108.    
  109. }