<mosaic.cnfolio.com>
PROGRAM
  1. /*Sam Smyth UP809997
  2. PSUEDO CODE
  3.  
  4. START
  5.    SET bets value to zero
  6.    WHILE bets value is less than 4
  7.       Scan for bet number
  8.       Scan for stake
  9.       Display users bet and stake
  10.       Generate random number
  11.       IF random number equals users bet
  12.          THEN
  13.             Update users balance with winnings
  14.             Display winnings and updated balance to user
  15.          ELSE
  16.             Subract stake from balance
  17.             DIsplay losings and new balance
  18.       END IF
  19.       Increase bets value by 1
  20.    END WHILE
  21. END
  22. */
  23.  
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <time.h>
  28.  
  29. /*Define the function get_num*/
  30. int get_num(void);
  31.  
  32. int main(void)
  33. {   
  34.    /*Define all variables to be used in main*/
  35.    int singlebet;
  36.    int stake;
  37.    /*This variable will help monitor how many bets/spins have taken place*/
  38.    int bets = 0;
  39.    int balance = 0;
  40.    int result;
  41.    
  42.    /*Seeding of srand*/
  43.    srand(time(NULL));
  44.    
  45.    printf("WELCOME TO MY ROULETTE GAME.\nPlease note: You may bet on any number between 0 and 37 (37 acting as 00)\n");
  46.    
  47.    /*This while loop will continue to loop until the bets value reaches 4*/
  48.    while (bets < 4)
  49.    {
  50.       /*Scanning for chosen number*/
  51.       scanf("%d", &singlebet);
  52.       /*Scanning for stake value*/
  53.       scanf("%d", &stake);
  54.       /*Informing the user of their chosen bet*/
  55.       printf("You have placed %d chips on the number %d, Good Luck!", stake, singlebet);
  56.      
  57.       /*Retrieving the random number from the get_num function*/     
  58.       result = get_num() - 1;
  59.                /*Comparing the roullete result with the users bet*/
  60.                if (result==singlebet)
  61.                  {
  62.                  /*Increase users balance*/
  63.                  balance += (stake*35);
  64.                  /*Informing the user of their winnings and their new balance*/
  65.                  printf("You Won %d chips! You current stack total is %d chips.\n\n", (stake*35), balance);
  66.                  }
  67.                /*If user was to lose*/
  68.                else
  69.                  {
  70.                   /*Decrease users balance by their chosen stake*/
  71.                   balance -= stake;
  72.                   /*Inform user of their lose and updated balance*/
  73.                   printf("Unlucky! You lose %d chips. Your new stack total is %d chips.\n\n", stake, balance);
  74.                  }     
  75.       /*Increase bets value by 1, to ensure the while loop ends after 4 loops*/
  76.       bets += 1;                       
  77.    } 
  78.    printf("Your final stack total is %d. Thank you for playing!", balance);
  79. }
  80.  
  81. /*Random number generator function*/
  82. int get_num (void)
  83. {
  84.     /*Define variable*/
  85.     int number;
  86.     /*Number generator, from 0-37 (36 being 00)*/
  87.     number=1+(rand()%38);
  88.     /*Informing the user of the chosen number*/
  89.     printf("\nBall has landed on %d!\n", (number-1));
  90.     /*Give back the random number to be used to decide whether the user has won*/
  91.     return number;
  92. }