<mosaic.cnfolio.com>
PROGRAM
  1. /* Pseudo Code
  2. START
  3. Player must choose 4 numbers between 0 and 37
  4. Player places 4 bets
  5. Set total profit to 0
  6.  
  7. IF player has incorrect input values
  8. THEN
  9.     roulette will not allow player to spin
  10.  
  11. IF bet number is not between 0 and 37
  12. THEN   
  13.     roulette will not be allowed to spin
  14. END IF
  15.  
  16. Display errors where necessary
  17.  
  18. WHILE bet number is between 0 and 37
  19. spin roulette
  20. generate random number
  21.  
  22. IF first bet number is the same as the random number
  23. THEN
  24.     players bet wins and therefore payout the stake multiplied by 35
  25. ELSE
  26.     players bet loses and they dont win anything
  27.  
  28. Display profit/loss for this particular bet
  29.  
  30. IF second bet number is the same as the random number
  31. THEN
  32.     players bet wins and therefore payout the stake multiplied by 35
  33. ELSE   
  34.     p players bet loses and they dont win anything
  35.    
  36. Display profit/loss for this particular bet
  37.  
  38. IF third bet number is the same as the random number
  39. THEN
  40.     players bet wins and therefore payout the stake multiplied by 35
  41. ELSE
  42.      players bet loses and they dont win anything
  43.    
  44. Display profit/loss for this particular bet
  45.  
  46. IF fourth bet number is the same as the random number
  47. THEN
  48.     players bet wins and therefore payout the stake multiplied by 35
  49. ELSE
  50.      players bet loses and they dont win anything
  51. END IF
  52.  
  53. Display profit/loss for this particular bet
  54.  
  55. Display total profit/loss for all four bets combined
  56.  
  57. */
  58.  
  59.  
  60.  
  61. #include <stdio.h>
  62. #include <time.h>         
  63. #include <stdlib.h>
  64. int main ()
  65. {
  66.  
  67. int bets[4][2]; /* Sets the array */
  68. int totalProfit = 0;
  69. int numVariables;
  70. time_t t;
  71. int errors = 0;
  72.  
  73. printf("Enter 4 bets choosing 4 number between 0 and 37 (Where 37 is 00) and enter a stake for each 4 bets : \n");
  74. numVariables=scanf("%d %d %d %d %d %d %d %d", &bets[0][0], &bets[0][1], &bets[1][0], &bets[1][1], &bets[2][0], &bets[2][1], &bets[3][0], &bets[3][1]);
  75.  
  76. for( int i = 0 ; i < 4 ; i++ ) {
  77.  
  78. if (numVariables != 8) /* numVariables value set to 8 so that we know 8 inputs is all the program will allow */
  79. {
  80. printf("Must enter only 8 integers \n"); /* Error checking which will make sure 8 integers are entered at all times */
  81. errors = 1;
  82. break;
  83. }
  84.  
  85. if (bets[i][0] < 0)
  86. {
  87. printf("\nBet is invalid as number cannot be less than 0 \n");
  88. errors = 1; /* when errors is equal to 1 to code should not run */
  89. }
  90. if (bets[i][0] > 37)
  91. {
  92. printf("\nBet is invalid as number cannot be more than 37 \n");
  93. errors = 1;
  94. }
  95.  
  96. if (bets[i][1] < 1)
  97. {
  98. printf("\nBet stake cannot be less than 1 \n");
  99. errors = 1;
  100. }
  101.  
  102. }
  103.  
  104.  
  105. if(errors == 0) /* when the code finds no errors within the input it can run successfully */
  106. {
  107.  
  108. srand((unsigned) time(&t)); /* This function starts up the random number generator */
  109.  
  110. for( int i = 0 ; i < 4 ; i++ ) { /* The for loop will stop running after 4 bets have been placed */
  111.  
  112. int winningNum = rand() % 37; /* Assume that '00' is represented by 37 */
  113.  
  114. int won = 0; /* default for loss of bet */
  115. int payout = 0;
  116. int netProfit = 0;
  117. int betNumber = bets[i][0];
  118. int betStake = bets[i][1]; /* takes corresponding the number for each time the loop runs until it finishes */
  119.  
  120. if (winningNum == betNumber) {
  121. won = 1; /* Sets value to true which means the bet has won */
  122. payout = betStake * 35; /* betStake is multiplied by 35 because the bet has won and the odds for one number are 35/1 */
  123. netProfit = payout + betStake;
  124. } else{
  125. won = 0; /* Sets value to false */
  126. payout = betStake * 0; /* betStake is multiplied by 0 because the bet has lost */
  127. netProfit = payout - betStake;
  128. }
  129. totalProfit = totalProfit + netProfit;
  130.  
  131. printf("\nBET %d \nBet Number : %d\nYour Stake : %d \nWinning Number : %d \nYour Payout : %d \nNet Profit/Loss : %d \n", i+1, betNumber, betStake, winningNum, payout, netProfit);
  132.  
  133. }
  134.  
  135. printf("\nTotal Profit/Loss : %d\n", totalProfit);
  136.  
  137. }
  138. }