<mosaic.cnfolio.com>
PROGRAM
  1. /* START
  2.  
  3. IF bets = 4 AND
  4.    bet number between 1 and 36 AND
  5.    bet amount is a whole number THEN
  6.    Spin roulette wheel with american format // Spin wheel using table with pockets for 0 to 36 plus a pocket for 00
  7.    Display winning number for first bet
  8.    
  9. IF bet number equals winning number
  10.  
  11.  
  12. THEN
  13.    Add bet amount to remaining balance
  14.    Add bet amount multiplied by 35 to balance
  15.    
  16. ELSE
  17.    Subtract bet amount from balance
  18. END IF
  19.  
  20. Display winning number for second bet
  21.  
  22. IF bet number equals winning number
  23.  
  24. THEN
  25.    Add bet amount to remaining balance
  26.    Add bet amount multiplied by 35 to balance
  27.    
  28. ELSE
  29.    Subtract bet amount from balance
  30. END IF
  31.  
  32. Display winning number for third bet
  33.  
  34. IF bet number equals winning number
  35.  
  36. THEN
  37.    Add bet amount to remaining balance
  38.    Add bet amount multiplied by 35 to balance
  39.    
  40. ELSE
  41.    Subtract bet amount from balance
  42. END IF
  43.  
  44. Display winning number for fourth bet
  45.  
  46. IF bet number equals winning number
  47.  
  48. THEN
  49.    Add bet amount to remaining balance
  50.    Add bet amount multiplied by 35 to balance
  51.    
  52. ELSE
  53.    Subtract bet amount from balance
  54. END IF
  55.  
  56.    Display total winnings and loss
  57. IF winnings are bigger than loss
  58. THEN display remaining balance
  59. ELSE
  60.    Display final balance after calculating winnings and losses
  61. END IF
  62. END IF
  63. ELSE
  64.    Failed to input 4 bets exiting game
  65. END */
  66.    
  67.    
  68.  
  69.  
  70.  
  71. #include <stdio.h>
  72. #include <stdlib.h>
  73.  
  74. int main(void)
  75. {
  76.  
  77.   // Integer Variables
  78.   int i,j,k,l;   
  79.   int m,n,o,p;   
  80.   int r;
  81.   int rng1,rng2,rng3,rng4;
  82.   int win1,win2,win3,win4;
  83.   int loss1,loss2,loss3,loss4;
  84.   int startingbalance = 500;
  85.   int remainingbalance;
  86.   int losstotal;
  87.   int wintotal;
  88.   int finalamount;
  89.  
  90.   // Introduction to the game
  91.   printf("Welcome to the Roulette game, your balance is at 500, you may bet with this amount on 4 bets\n");
  92.   printf("Good luck\n");
  93.  
  94.  
  95.   printf("Input a bet and a bet amount for each of the 4 rounds\n "); // Ask for 4 input pairs
  96.  
  97.  
  98.   //Bet Input and Condition check
  99.   if  (scanf("%d%d%d%d%d%d%d%d", &i, &m, &j, &n, &k, &o, &l, &p) == 8 && i >= 1 && i < 37 && j >= 1 && j < 37 && k >=1 && k < 37 && l >= 1 && l < 37 && m >= 5 && n >= 5 && o >= 5 && p >= 5 && m + n + o + p < startingbalance )
  100.     {
  101.     printf ("Bet1 : %d on number %d\n Bet2 : %d on number %d\n Bet3 : %d on number %d\n Bet4 : %d on number %d\n", m, i, n, j, o, k, p, l);
  102.    
  103.     (remainingbalance = (startingbalance - m - n - o - p)); //Take bet money from balance
  104.  
  105.  // Seed number in generator
  106.   srand(time(NULL));
  107.    
  108.   // Generate a random number within the range of 0 and 36 for first spin
  109.   for (r=0; r<1; r++){
  110.    
  111.   rng1 = ( rand() % 38);                                 
  112.  
  113.   printf("The payout for your first bet is 35 to 1\n")// Displaying payout value
  114.  
  115.   //Implementing 00 for bet1
  116.   if (rng1 == 37 ) {             
  117.   printf("The ball stopped on 00\n");
  118.   }
  119.   else {
  120.   printf(" The ball stopped on %d \n", rng1);
  121. }
  122.   // Displaying Bet1 results
  123.   if (rng1==i)                          // Check for winning number
  124.   {
  125.       win1 = ( ( m * 35 ) + m );               
  126.       printf("Your %d bet on number %d earned you %d\n", m, i, win1);
  127.       (loss1 = 0);
  128.   }
  129.   else
  130.     {
  131.       printf("Unfortunately you lost, %d have been subtracted from your balance\n", m);
  132.       (loss1 = m);
  133.       (win1 = 0);
  134.         }
  135.     }
  136.   // Generate a random number within the range of 0 and 36 for second spin
  137.   for (r=0; r<1; r++){
  138.    
  139.   rng2 = ( rand() % 38);
  140.  
  141.   printf("The payout for your second bet is 35 to 1\n");
  142.   if (rng2 == 37 ) {
  143.   printf("The ball stopped on 00\n");
  144.   }
  145.   else {
  146.   printf(" The ball stopped on %d \n", rng2);
  147. }
  148.   // Displaying Bet2 results
  149.   if (rng2==j)
  150.   {
  151.     win2 = ( ( n * 35 ) + n );
  152.     printf("Your %d bet on number %d earned you %d\n", n, j, win2);
  153.     (loss2 = 0 );
  154.   }
  155.   else
  156.     {
  157.     printf("Unfortunately you lost, %d have been subtracted from your balance\n", n);
  158.     (loss2 = n);
  159.     (win2 = 0);
  160.     }
  161.        }
  162.   // Generate a random number within the range of 0 and 36 for third spin
  163.   for (r=0; r<1; r++){
  164.    
  165.   rng3 = ( rand() % 38);
  166.  
  167.   printf("The payout for your third bet is 35 to 1\n");
  168.   if (rng3 == 37 ) {
  169.   printf("The ball stopped on 00\n");
  170.   }
  171.   else {
  172.   printf(" The ball stopped on %d \n", rng3);
  173. }
  174.   // Displaying Bet3 results
  175.   if (rng3==k)
  176.   {
  177.     win3 = ( ( o * 35 ) + o );
  178.     printf("Your %d bet on number %d earned you %d\n", o, k, win3);
  179.     (loss3 = 0);
  180.   }
  181.   else
  182.     {
  183.     printf("Unfortunately you lost, %d have been subtracted from your balance\n", o);
  184.     (loss3 = o);
  185.     (win3 = 0);
  186.     }
  187.        }
  188.   // Generate a random number within the range of 0 and 36 for fourth spin
  189.   for (r=0; r<1; r++){
  190.    
  191.   rng4 = ( rand() % 38);
  192.  
  193.   printf("The payout for your fourth bet is 35 to 1\n");
  194.   if (rng4 == 37 ) {
  195.   printf("The ball stopped on 00\n");
  196.   }
  197.   else {
  198.   printf(" The ball stopped on %d \n", rng4);
  199. }
  200.   // Displaying Bet4 results
  201.   if (rng4==l)
  202.   {
  203.     win4 = ( ( p * 35 ) + p );
  204.     printf("Your %d bet on number %d earned you %d\n", p, j, win4);
  205.     (loss4 = 0);
  206.   }
  207.   else
  208.     {
  209.     printf("Unfortunately you lost, %d have been subtracted from your balance\n", p);
  210.     (loss4 = p);
  211.     (win4 = 0);
  212.     }
  213.        }
  214.   // Calculate total loss or winnings
  215.  
  216.   (wintotal = ( (win1 + win2 + win3 + win4) - (loss1 + loss2 + loss3 + loss4)));
  217.   if (wintotal > 0) {
  218.    printf("Thank you for playing roulette, you won %d leaving you with %d", wintotal, (wintotal + remainingbalance));
  219.    }
  220.    
  221.   else {
  222.    printf("Thank you for playing roulette, you lost %d leaving you with %d", (startingbalance - remainingbalance), remainingbalance);
  223.    }
  224.    }
  225.    else {
  226.    printf("You failed to enter 4 correct bet numbers and bets\n")//Terminating game if inputs are incorrect
  227.    exit (0);   
  228.    }
  229.   }