<mosaic.cnfolio.com>

- /* Pseudo Code
- START
- Player must choose 4 numbers between 0 and 37
- Player places 4 bets
- Set total profit to 0
- IF player has incorrect input values
- THEN
- roulette will not allow player to spin
- IF bet number is not between 0 and 37
- THEN
- roulette will not be allowed to spin
- END IF
- Display errors where necessary
- WHILE bet number is between 0 and 37
- spin roulette
- generate random number
- IF first bet number is the same as the random number
- THEN
- players bet wins and therefore payout the stake multiplied by 35
- ELSE
- players bet loses and they dont win anything
- Display profit/loss for this particular bet
- IF second bet number is the same as the random number
- THEN
- players bet wins and therefore payout the stake multiplied by 35
- ELSE
- p players bet loses and they dont win anything
- Display profit/loss for this particular bet
- IF third bet number is the same as the random number
- THEN
- players bet wins and therefore payout the stake multiplied by 35
- ELSE
- players bet loses and they dont win anything
- Display profit/loss for this particular bet
- IF fourth bet number is the same as the random number
- THEN
- players bet wins and therefore payout the stake multiplied by 35
- ELSE
- players bet loses and they dont win anything
- END IF
- Display profit/loss for this particular bet
- Display total profit/loss for all four bets combined
- */
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- int main ()
- {
- int bets[4][2]; /* Sets the array */
- int totalProfit = 0;
- int numVariables;
- time_t t;
- int errors = 0;
- printf("Enter 4 bets choosing 4 number between 0 and 37 (Where 37 is 00) and enter a stake for each 4 bets : \n");
- 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]);
- for( int i = 0 ; i < 4 ; i++ ) {
- if (numVariables != 8) /* numVariables value set to 8 so that we know 8 inputs is all the program will allow */
- {
- printf("Must enter only 8 integers \n"); /* Error checking which will make sure 8 integers are entered at all times */
- errors = 1;
- break;
- }
- if (bets[i][0] < 0)
- {
- errors = 1; /* when errors is equal to 1 to code should not run */
- }
- if (bets[i][0] > 37)
- {
- errors = 1;
- }
- if (bets[i][1] < 1)
- {
- errors = 1;
- }
- }
- if(errors == 0) /* when the code finds no errors within the input it can run successfully */
- {
- srand((unsigned) time(&t)); /* This function starts up the random number generator */
- for( int i = 0 ; i < 4 ; i++ ) { /* The for loop will stop running after 4 bets have been placed */
- int winningNum = rand() % 37; /* Assume that '00' is represented by 37 */
- int won = 0; /* default for loss of bet */
- int payout = 0;
- int netProfit = 0;
- int betNumber = bets[i][0];
- int betStake = bets[i][1]; /* takes corresponding the number for each time the loop runs until it finishes */
- if (winningNum == betNumber) {
- won = 1; /* Sets value to true which means the bet has won */
- payout = betStake * 35; /* betStake is multiplied by 35 because the bet has won and the odds for one number are 35/1 */
- netProfit = payout + betStake;
- } else{
- won = 0; /* Sets value to false */
- payout = betStake * 0; /* betStake is multiplied by 0 because the bet has lost */
- netProfit = payout - betStake;
- }
- totalProfit = totalProfit + netProfit;
- 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);
- }
- }
- }