<mosaic.cnfolio.com>
PROGRAM
  1. #include <stdlib.h>
  2. #include <time.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. /*
  7. START
  8.     get all the bets and the numbers they have been placed on
  9.    
  10.     IF any of the numbers are less than 0
  11.      THEN OUTPUT "Enter integers greater than 0 for bets and numbers"
  12.    
  13.     ELSE
  14.      
  15.       IF any numbers are greater than 36
  16.          THEN OUTPUT "Enter numbers less than 36 for numbers"
  17.      
  18.       ELSE
  19.          WHILE the number of spins is less than 4
  20.             generate a random number between 0 and 37 inclusive
  21.            
  22.             IF the random number is equal to the next number
  23.                THEN OUTPUT "the ball landeed in "
  24.                OUTPUT the random number
  25.                OUTPUT "your bet won!"
  26.                multiply the bet by 35 and add it to the total
  27.            
  28.             ELSE IF the random number is 37
  29.                THEN PRINT "The ball landed in 00. Your bet lost!"
  30.            
  31.             ELSE
  32.                OUTPUT "The ball landed in "
  33.                OUTPUT the random number
  34.                OUTPUT "Your bet lost!"
  35.                take the bet away from the total
  36.             END IF
  37.            
  38.             OUTPUT the current total
  39.          END WHILE
  40.      END IF
  41.   END IF
  42.  
  43.   OUTPUT "your final total is"
  44.   OUTPUT the total
  45.            
  46. END
  47. */
  48.  
  49. int total=0, spins=1;   
  50. int number1=-1, bet1=-1, number2=-1, bet2=-1, number3=-1, bet3=-1, number4=-1, bet4=-1, limit=50000;
  51. char *color[37]={'G','R','B','R','B','R','B','R','B','R','B','B','R','B','R','B','R','B','R','R','B','R','B','R','B','R','B','R','B','B','R','B','R','B','R','B','R','B','R'};
  52. //This array matches the index number with the colour that number represents on a roulette table
  53.  
  54.  
  55. int main (void)
  56. {     
  57.    srand(time(0));
  58.    scanf("%d %d %d %d %d %d %d %d", &bet1, &number1, &bet2, &number2, &bet3, &number3, &bet4, &number4);
  59.    
  60.   if ((bet1>0)&&(bet2>0)&&(bet3>0)&&(bet4>0)&&(number1>=0)&&(number2>=0)&&(number3>=0)&&(number4>=0)) 
  61.     {
  62.       if ((number1<37)&&(number2<37)&&(number3<37)&&(number4<37))    // I seperated these if statements so that I could give more specific errors
  63.       {
  64.          if ((number1<=limit)&&(number2<=limit)&&(number3<=limit)&&(number4<=limit))
  65.          {
  66.             spin(number1, bet1);
  67.             spin(number2, bet2);
  68.             spin(number3, bet3);
  69.             spin(number4, bet4);
  70.             printf("your overall total is %d. ", total);
  71.    
  72.             if (total>0)
  73.               printf("you played well! you should try again.");
  74.       else if ((total<1)&&(total>-500))
  75.                printf("you didn't do too well. You should play again to make up your losses.");
  76.             else
  77.                printf("You should never go anywhere near a casino!");
  78.          }
  79.          else printf(" You have exceeded the casino limit.");
  80.          
  81.        }
  82.        
  83.        else printf("You can only bet on numbers between 0 and 36, and 00.");   
  84.    }
  85.    else printf(" please enter integers greater than 0");
  86.  }
  87.  
  88.    
  89. int spin(int number, int bet) // I used a function to spin the roulette wheel because it takes up less space and is easier to read than writing each line out four times
  90. {
  91.    int result;
  92.    result = (rand()%38);
  93.    
  94.    if (result==37) printf("Ball number %d lands in 00(G). \nYou put %d on %d", spins, bet, number);
  95.    
  96.    else printf("Ball number %d lands in %d(%c). \nYou put %d on %d. ", spins, result, color[result], bet, number);
  97.  
  98.    if (number == result)
  99.    {
  100.       total=total+(bet*36);
  101.       printf("You won %d!", bet*35);
  102.    }
  103.    /*else if (number==color[result])
  104.    {
  105.       total=total+(bet*2);
  106.       printf("You won %d!", bet*2);
  107.    }*/
  108.    else
  109.    {
  110.        printf("\nBetter luck next time!");
  111.       total=total-bet;
  112.    }
  113.    printf("\nYour current total is %d\n\n", total);
  114.    spins+=1;
  115. }