<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. START
  3.    Set number of bets to 0
  4.    WHILE number of bets is less than 4
  5.       Get bet number and amount
  6.       IF bet number is between 0 and 36 AND bet value is a positive integer
  7.          THEN
  8.          Spin American roulette wheel with a 00 on the wheel
  9.          Display the bet number chosen
  10.          Display the bet amount for that bet
  11.          Generate random winning number
  12.          Display winning number
  13.          IF bet number equals winning number
  14.             THEN
  15.                Add bet amount to subtotal
  16.                Add bet amount multiplied by 35 to subtotal
  17.                Display payout value for bet
  18.           ELSE
  19.                Subtract bet amount from subtotal
  20.             Display 0 as payout value
  21.        END IF
  22.       ELSE
  23.          Display error message due to incorrect bet input values
  24.       END IF
  25.          Display subtotal
  26.          Increse number of bets by 1
  27.       END WHILE
  28.       IF number of best is less than 4
  29.          THEN
  30.           Display an error message due to lack of bet numbers input
  31.       END IF
  32.    Display subtotal as total
  33. END
  34. */
  35.  
  36. #include <stdio.h> /* Defines the stdio (standard input/output) header file for the program to use */
  37. #include <time.h>  /* Defines the time header file so that the program is able to generate random numbers for the spins */
  38. #include <unistd.h> /* Defines the unistd header file to allow for the use of the sleep() function. This is used to insert a delay between random number generation so that 4 identical numbers are not generated*/
  39.  
  40.  
  41. int main ( void ) /* Defines the main function of the program. The program ends when the main function finishes. */
  42. {
  43.  
  44. int betnumber1=-1; /* The following 4 variables hold the value of the four bet numbers */
  45. int betnumber2=-1; /* These are set to -1 for error checking. (Not set to 0 because 0 is a valid bet number) */
  46. int betnumber3=-1;
  47. int betnumber4=-1;
  48. int betamount1=0; /* The following 4 variables hold the value of the four bet amounts */
  49. int betamount2=0; /* These are set to 0 for error checking */
  50. int betamount3=0;
  51. int betamount4=0;
  52. int bet1winnings=0; /* The following 4 variables store the winnings amounts for the 4 bets to be added to the player's wallet if they win */
  53. int bet2winnings=0;
  54. int bet3winnings=0;
  55. int bet4winnings=0;
  56. int winningnumber1=0; /* The following 4 variables store the winning numbers for each of the spins */
  57. int winningnumber2=0;
  58. int winningnumber3=0;
  59. int winningnumber4=0;
  60. int totalbetamount=0; /* This variable stores the total winnings of the player */
  61. int subtotal=0; /* This variable stores the running winnings amount to be shown after each bet */
  62.  
  63. scanf("%d %d %d %d %d %d %d %d", &betnumber1, &betamount1, &betnumber2, &betamount2, &betnumber3, &betamount3, &betnumber4, &betamount4); /* Looks for and assigns values for bet numbers and bet amounts to their respective varialbes */
  64.  
  65. if(betnumber1<0 || betnumber2<0 || betnumber3<0 || betnumber4<0 || betnumber1>37 || betnumber2>37 || betnumber3>37 || betnumber4>37) /* Error checking to make sure that 4 bet numbers have been input and that they are valid. (0 or greater and less than or equal to 37) */
  66.    {
  67.    printf("\nPlease enter 4 bets between 0 and 37 and 4 bet amounts using the following format:\n\nbet amount bet amount bet amount bet amount"); /* This message will be shown when any of the 4 bet numbers are invalid, encouraging the user to input 4 valid values */
  68.    }
  69. else if(betamount1<1 || betamount2<1 || betamount3<1 || betamount4<1) /* If the bet numbers pass the error checking, the bet amounts will be checked to make sure that the input value is greater than 0 */
  70.    {
  71.    printf("\nPlease enter 4 bet amounts greater than 0."); /* If any of the bet amounts are less than 0 or are blank, this error message will be displayed */
  72.    }
  73. else
  74.    {
  75.    printf("Welcome to roulette!"); /* Welcome message to signal the start of the spins */
  76.    printf("\nYour bet numbers are: %d %d %d %d", betnumber1, betnumber2, betnumber3, betnumber4); /* Displays the 4 bet numbers that the user has inputted */
  77.    printf("\nYour bet amounts are: %d %d %d %d", betamount1, betamount2, betamount3, betamount4); /* Displays the 4 bet amounts that the user has inputted */
  78.    srand (time(0)); /* Seeds the random number generator */
  79.    winningnumber1 = rand()%38; /* A random number is generated between 0 and 37, then is assigned to the variable 'winningnumber1' */
  80.    printf("\n\n--Spin 1--"); /* Displays a header for spin 1 */
  81.    printf("\nYour bet number was %d, and bet amount was %d.",betnumber1, betamount1); /* Displays the bet numbers and bet amounts for spin 1 */
  82.    printf("\nWinning number for spin 1 is: %d", winningnumber1); /* Displays the winning number for spin 1 */
  83.    if(winningnumber1==betnumber1) /* Decides whether or not the user has selected the correct bet number for spin 1 */
  84.       {
  85.       bet1winnings = betamount1*36; /* Multiplies the bet amount by the payout (35:1) plus the original bet amount and assigns it to the variable bet1winnings */
  86.       subtotal=subtotal+bet1winnings; /* Assigns the value of bet1winnings (the payout of spin 1) to the variable subtotal to keep a running net profit/loss */
  87.       printf("\nCongratulations, your first bet was correct! The payout for this bet is %d. (35:1) ", bet1winnings); /* Congratulatory message to the player. Displays the payout for spin 1 */
  88.       } 
  89.       else printf("\nSorry, your bet was not correct.\nThe payout for this bet was 0\nYour subtotal net profit/loss is %d", subtotal=subtotal-betamount1)/* Displays message to the player that they have not won on this spin. Also displays the net profit/loss */
  90.  
  91.      
  92.    sleep(1); /* Halts the program for 1 second to ensure that the next random number is not the same as the previous */
  93.    srand (time(0));/* Seeds the random number generator */
  94.    winningnumber2 = rand()%38; /* A random number is generated between 0 and 37, then is assigned to the variable 'winningnumber2' */
  95.    printf("\n\n--Spin 2--"); /* Displays a header for spin 2 */
  96.    printf("\nYour bet number was %d, and bet amount was %d.",betnumber2, betamount2); /* Displays the bet numbers and bet amounts for spin 2 */
  97.    printf("\nWinning number for spin 2 is: %d", winningnumber2); /* Displays the winning number for spin 2 */
  98.    if(winningnumber2==betnumber2) /* Decides whether or not the user has selected the correct bet number for spin 2 */
  99.       {
  100.       bet2winnings = betamount2*36; /* Multiplies the bet amount by the payout (35:1) plus the original bet amount and assigns it to the variable bet2winnings */
  101.       subtotal=subtotal+bet2winnings; /* Assigns the value of bet2winnings (the payout of spin 2) to the variable subtotal to keep a running net profit/loss */
  102.       printf("\nCongratulations, your second bet was correct! The payout for this bet is %d. (35:1) ", bet2winnings); /* Congratulatory message to the player. Displays the payout for spin 2 */
  103.       } 
  104.       else printf("\nSorry, your bet was not correct.\nThe payout for this bet was 0\nYour subtotal net profit/loss is %d", subtotal=subtotal-betamount2)/* Displays message to the player that they have not won on this spin. Also displays the net profit/loss */
  105.      
  106.    sleep(1); /* Halts the program for 1 second to ensure that the next random number is not the same as the previous */
  107.    srand (time(0)); /* Seeds the random number generator */
  108.    winningnumber3 = rand()%38; /* A random number is generated between 0 and 37, then is assigned to the variable 'winningnumber3' */
  109.    printf("\n\n--Spin 3--"); /* Displays a header for spin 3 */
  110.    printf("\nYour bet number was %d, and bet amount was %d.",betnumber3, betamount3); /* Displays the bet numbers and bet amounts for spin 3 */
  111.    printf("\nWinning number for spin 3 is: %d", winningnumber3); /* Displays the winning number for spin 3 */
  112.    if(winningnumber3==betnumber3) /* Decides whether or not the user has selected the correct bet number for spin 3 */
  113.       {
  114.       bet3winnings = betamount3*36; /* Multiplies the bet amount by the payout (35:1) plus the original bet amount and assigns it to the variable bet3winnings */
  115.       subtotal=subtotal+bet3winnings; /* Assigns the value of bet3winnings (the payout of spin 3) to the variable subtotal to keep a running net profit/loss */
  116.       printf("\nCongratulations, your third bet was correct! The payout for this bet is %d. (35:1) ", bet3winnings); /* Congratulatory message to the player. Displays the payout for spin 3 */
  117.       } 
  118.       else printf("\nSorry, your bet was not correct.\nThe payout for this bet was 0\nYour subtotal net profit/loss is %d", subtotal=subtotal-betamount3); /* Displays message to the player that they have not won on this spin. Also displays the net profit/loss */
  119.      
  120.    sleep(1); /* Halts the program for 1 second to ensure that the next random number is not the same as the previous */
  121.    srand (time(0)); /* Seeds the random number generator */
  122.    winningnumber4 = rand()%38; /* A random number is generated between 0 and 37, then is assigned to the variable 'winningnumber4' */
  123.    printf("\n\n--Spin 4--"); /* Displays a header for spin 4 */
  124.    printf("\nYour bet number was %d, and bet amount was %d.",betnumber4, betamount4); /* Displays the bet numbers and bet amounts for spin 4 */
  125.    printf("\nWinning number for spin 4 is: %d", winningnumber4); /* Displays the winning number for spin 4 */
  126.    if(winningnumber4==betnumber4) /* Decides whether or not the user has selected the correct bet number for spin 4 */
  127.       {
  128.       bet4winnings = betamount4*36; /* Multiplies the bet amount by the payout (35:1) plus the original bet amount and assigns it to the variable bet4winnings */
  129.       subtotal=subtotal+bet4winnings; /* Assigns the value of bet4winnings (the payout of spin 4) to the variable subtotal to keep a running net profit/loss */
  130.       printf("\nCongratulations, your fourth bet was correct! The payout for this bet is %d. (35:1) ", bet4winnings); /* Congratulatory message to the player. Displays the payout for spin 4 */
  131.       } 
  132.       else printf("\nSorry, your bet was not correct.\nThe payout for this bet was 0\nYour subtotal net profit/loss is %d", subtotal=subtotal-betamount4); /* Displays message to the player that they have not won on this spin. Also displays the net profit/loss */
  133.      
  134.    printf("\n\nYour total profit/loss over the 4 bets is %d",subtotal); /* Displays the total profit/loss over the 4 spins to the player */
  135.    }
  136. }