<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. Declare BetNumber 1, 2, 3 and 4
  3. Declare BetAmount 1, 2, 3 and 4
  4. Declare BetProfit 1, 2, 3 and 4
  5. Declare WinningNumber 1, 2, 3 and 4
  6. Declare TotalProfit
  7. Declare TotalBet
  8. Declare Total
  9.  
  10. Display message "Please enter four pairs of numbers. The first number of a pair being the bet number, and the second number
  11. of the pair being the amount you'd like to bet for the previous bet number. Bet numbers must be at least 0 and no higher than 37 --
  12. 37 representing 0. Bet amounts cannot be lower than 1."
  13.  
  14. Read eight Inputs (BetNumber1, BetAmount1, BetNumber2, BetAmount2, BetNumber3, BetAmount 3, BetNumber4, BetAmount4)
  15.  
  16. IF (BetNumber 1, 2, 3 or 4 are under 0 or above 37)
  17.     Display "Bet numbers must be above 0 but cannot exceed 37"
  18. ELSE
  19.  
  20. IF (BetAmount 1, 2, 3 or 4 are below 1)
  21.     Display "Bet amounts must be at least 1"
  22.  
  23. ELSE
  24.  
  25.  
  26. Display "You have bet BetAmount1 on BetNumber1, BetAmount2 on BetNumber2, BetAmount3 on BetNumber3, & BetAmount4 on BetNumber4"
  27. Generate random number between 0 and 37 and save to WinningNumber1
  28. Display "BET 1:"
  29. Display "You bet *BetAmount1* on *BetNumber1*"
  30. IF BetNumber1 = WinningNumber1
  31.    Multiply BetAmount1 by 35 and set to BetProfit1
  32.    Total = Total + BetProfit1
  33.    Display "Winner! Your payout for bet 1 is *BetProfit1*"
  34.   ELSE
  35.    Total = Total - BetAmount1
  36.    Display "Incorrect! Your total loss so far is *Total*"
  37.    
  38. Wait 1 second   
  39. Generate random number between 0 and 37 and save to WinningNumber2
  40. Display "BET 2:"
  41. Display "You bet *BetAmount2* on *BetNumber2*"
  42. IF BetNumber2 = WinningNumber2
  43.    Multiply BetAmount2 by 35 and set to BetProfit2
  44.    Total = Total + BetProfit2
  45.    Display "Winner! Your payout for bet 2 is *BetProfit2*"
  46.   ELSE
  47.    Total = Total - BetAmount1
  48.    Display "Incorrect! Your total win/loss so far is *Total*"
  49.    
  50. Wait 1 second
  51. Generate random number between 0 and 37 and save to WinningNumber3
  52. Display "BET 3:"
  53. Display "You bet *BetAmount3* on *BetNumber3*"
  54. IF BetNumber3 = WinningNumber3
  55.    Multiply BetAmount3 by 35 and set to BetProfit3
  56.    Total = Total + BetProfit3
  57.    Display "Winner! Your payout for bet 3 is *BetProfit3*"
  58.   ELSE
  59.    Total = Total - BetAmount3
  60.    Display "Incorrect! Your total win/loss so far is *Total*"
  61.  
  62. Wait 1 second
  63. Generate random number between 0 and 37 and save to WinningNumber4
  64. Display "BET 4:"
  65. Display "You bet *BetAmount4* on *BetNumber4*"
  66. IF BetNumber4 = WinningNumber4
  67.    Multiply BetAmount4 by 35 and set to BetProfit4
  68.    Total = Total + BetProfit4
  69.    Display "Winner! Your payout for bet 4 is *BetProfit4*"
  70.   ELSE
  71.    Total = Total - BetAmount4
  72.    Display "Incorrect! Your total win/loss so far is *Total*"
  73.  
  74. If Total is higer than TotalBet
  75. Display "Your total profit after the last bet is *TotalBet - Total*"
  76.  
  77. If Total is lower than 0
  78. Display "Your total loss after the last bet is *Total*"
  79.  
  80.  
  81.  
  82. */
  83.  
  84.  
  85. #include <stdio.h>
  86. #include <unistd.h>
  87. #include <time.h>
  88.  
  89.  
  90. int main ( void )
  91. {
  92.  
  93.  int BetNum[4]; /*Makes a bet number variable and sets it as an array with 5 values*/
  94.  int BetAmount[3]; /*Makes a bet amount variable and sets it as an array with 4 values*/
  95.  int BetProfit[3]; /*Makes a bet profit variable and sets it as an array with 4 values*/
  96.  int WinningNum[3]; /*Makes a winning number variable and sets it as an array with 4 values*/
  97.  int Total = 0; /*Makes a total variable and sets its value to 0*/
  98.  int TotalBet; /*Makes a total bet variable*/
  99.  int TotalProfit; /*Makes a total profit variable*/
  100.  
  101.  
  102.  scanf("%d %d %d %d %d %d %d %d", &BetNum[0], &BetAmount[0], &BetNum[1], &BetAmount[1], &BetNum[2], &BetAmount[2], &BetNum[3], &BetAmount[3]); /*Reads 8 user inputs. The inputs are recognised in the pattern "BetNumber, BetAmount, BetNumber, BetAmount, BetNumber, BetAmount, BetNumber, BetAmount"*/
  103.  
  104. if (BetNum[0] < 0 || BetNum[0] > 37 || BetNum[1] < 0 || BetNum[1] > 37 || BetNum[2] < 0 || BetNum[2] > 37 || BetNum[3] < 0 || BetNum[3] > 37)
  105.    {
  106.      printf("Please enter four bet numbers and four bet amounts in the format 'bet number, amount, bet number, amount'.\nBet numbers must be above 0 but cannot exceed 37"); /*This message will be displayed if any of the bet numbers are below 0 or exceed 37*/
  107.     }
  108.  else if (BetAmount[0] < 0 || BetAmount[1] < 0 || BetAmount[2] < 0 || BetAmount[3] < 0) /*If any of the bet amounts are 0 or lower, the following printf is displayed*/
  109.    {
  110.      printf("All bets must be at least 1"); /*Displays this if the user bet 0 or lower on any of the numbers*/
  111.    }
  112.  
  113. else
  114.  {
  115.   TotalBet = BetAmount[0] + BetAmount[1] + BetAmount[2] + BetAmount[3]; /*Adds all the bet amounts and sets it to the TotalBet variable*/
  116.   printf("You have bet a total of %d", TotalBet); /*Displays the total bet*/
  117.   printf("\nYou have bet %d on %d, %d on %d, %d on %d, and %d on %d", BetAmount[0], BetNum[0], BetAmount[1], BetNum[1], BetAmount[2], BetNum[2], BetAmount[3], BetNum[3]); /*Displays how much you've bet on each of the four numbers*/
  118.   srand(time(0)); /*Sets a starting value for the random number generation. In this case, it is 0*/
  119.   WinningNum[0] = rand()%38; /*Generates a random number from 0 to 38 and saves it to the variable, WinningNum[0]*/
  120.   printf("\n\nBET 1:"); /*Displays "BET 1"*/
  121.   printf("\nYou bet %d on %d", BetAmount[0], BetNum[0]); /*Displays how much you bet and on what number*/
  122.   if (WinningNum[0] == BetNum[0]) /*if the generated winning number for bet1 matches the bet amount for bet 1, then the following if statement if executed*/
  123.     {
  124.      BetProfit[0] = BetAmount[0]*35; /*Multiplies the bet amount of bet 1 to calculate the payout for bet 1*/
  125.      Total = Total + BetProfit[0]; /*Adds the payout of bet 1 to the variable, Total*/
  126.      printf("\nWinner! Your payout for bet 1 is %d", BetProfit[0]); /*Displays message informing user they've won the bet and displays the bet payout*/
  127.     }
  128.     else printf("\nIncorrect! The correct Winning number was %d.\nYour payout/loss so far is %d", WinningNum[0], Total = Total - BetAmount[0]); /*Informs the user they've lost the bet and displays the correct winning number and the payout so far. This is displayed if the winning number doesn't match the bet number*/
  129.  
  130.  
  131.   sleep(1); /*Waits 1 second so the random number generation doesn't generate the same number for each bet*/
  132.   srand(time(0)); /*Sets a starting value for the random number generation. In this case, it is 0*/
  133.   WinningNum[1] = rand()%38; /*Generates a random number from 0 to 38 and saves it to the variable, WinningNum[1]*/
  134.   printf("\n\nBET 2:");/*Displays "BET 2"*/
  135.   printf("\nYou bet %d on %d", BetAmount[1], BetNum[1]); /*Displays how much you bet and on what number*/
  136.   if (WinningNum[1] == BetNum[1]) /*if the generated winning number for bet 2 matches the bet amount for bet 2, then the following if statement if executed*/
  137.     {
  138.      BetProfit[1] = BetAmount[1]*35; /*Multiplies the bet amount of bet 2 to calculate the payout for bet 2*/
  139.      Total = Total + BetProfit[1]; /*Adds the payout of bet 2 to the variable, Total*/
  140.      printf("\nWinner! Your payout for bet 2 is %d", BetProfit[1]); /*Displays message informing user they've won the bet and displays the bet payout*/
  141.     }
  142.     else printf("\nIncorrect! The correct Winning number was %d.\nYour payout/loss so far is %d", WinningNum[1], Total = Total - BetAmount[1])/*Informs the user they've lost the bet and displays the correct winning number and the payout so far. This is displayed if the winning number doesn't match the bet number*/
  143.    
  144.  
  145.   sleep(1); /*Waits 1 second so the random number generation doesn't generate the same number for each bet*/
  146.   srand(time(0)); /*Sets a starting value for the random number generation. In this case, it is 0*/
  147.   WinningNum[2] = rand()%38; /*Generates a random number from 0 to 38 and saves it to the variable, WinningNum[2]*/
  148.   printf("\n\nBET 3:");/*Displays "BET 3"*/
  149.   printf("\nYou bet %d on %d", BetAmount[2], BetNum[2]); /*Displays how much you bet and on what number*/
  150.   if (WinningNum[2] == BetNum[2]) /*if the generated winning number for bet 3 matches the bet amount for bet 3, then the following if statement if executed*/
  151.     {
  152.      BetProfit[2] = BetAmount[2]*35; /*Multiplies the bet amount of bet 3 to calculate the payout for bet 3*/
  153.      Total = Total + BetProfit[2]; /*Adds the payout of bet 3 to the variable, Total*/
  154.      printf("\nWinner! Your payout for bet 3 is %d", BetProfit[2]); /*Displays message informing user they've won the bet and displays the bet payout*/
  155.     }
  156.     else printf("\nIncorrect! The correct Winning number was %d.\nYour payout/loss so far is %d", WinningNum[2], Total = Total - BetAmount[2]); /*Informs the user they've lost the bet and displays the correct winning number and the payout so far. This is displayed if the winning number doesn't match the bet number*/ 
  157.    
  158.    
  159.   sleep(1); /*Waits 1 second so the random number generation doesn't generate the same number for each bet*/
  160.   srand(time(0)); /*Sets a starting value for the random number generation. In this case, it is 0*/
  161.   WinningNum[3] = rand()%38; /*Generates a random number from 0 to 38 and saves it to the variable, WinningNum[3]*/
  162.   printf("\n\nBET 4:"); /*Displays "BET 4"*/
  163.   printf("\nYou bet %d on %d", BetAmount[3], BetNum[3]); /*Displays how much you bet and on what number*/
  164.   if (WinningNum[3] == BetNum[3]) /*if the generated winning number for bet 4 matches the bet amount for bet 4, then the following if statement if executed*/
  165.     {
  166.      BetProfit[3] = BetAmount[3]*35; /*Multiplies the bet amount of bet 4 to calculate the payout for bet 4*/
  167.      Total = Total + BetProfit[3]; /*Adds the payout of bet 4 to the variable, Total*/
  168.      printf("\nWinner! Your payout for bet 4 is %d", BetProfit[3]); /*Displays message informing user they've won the bet and displays the bet payout*/
  169.     }
  170.     else printf("\nIncorrect! The correct Winning number was %d.\nYour payout/loss so far is %d", WinningNum[3], Total = Total - BetAmount[3]); /*Informs the user they've lost the bet and displays the correct winning number and the payout so far. This is displayed if the winning number doesn't match the bet number*/
  171.    
  172.    
  173.    
  174.   if  (Total > TotalBet) /*Following if statement is executed if the total payout exceeds the total bet*/
  175.      {
  176.       printf("\n\nYour total payout after the four bets is %d", Total); /*Displays the total payout over the four bets*/
  177.       printf("\nCongratulations! Your total profit after the last bet is %d", TotalProfit = Total - TotalBet); /*Informs the player they've made a profit. Calculates profit gained by deducting the total bet from the total payout*/
  178.      }
  179.      else
  180.      
  181.      printf("\n\nSorry! Your loss totals to %d", Total); /*Informs the user that they have a total loss and displays how much they have lost. This is displayed if the total payout does not exceed the total bet*/
  182.      
  183.            
  184. }
  185. }