<mosaic.cnfolio.com>
PROGRAM
  1. /*START
  2.    user inputs 8 numbers in 4 pairs of bet numbers and bet amounts (37 IS DOUBLE ZERO)
  3.    IF the bet numbers and bet amounts are not whole numbers and the bet numbers are less than 0 or greater than 37
  4.       THEN
  5.             display error message stating how to input numbers and what has gone wrong
  6.       ELSE  
  7.          counter = 0
  8.             WHILE counter < 4
  9.                spin the roulette wheel 
  10.                   IF the bet numbers equal the winning number on the wheel
  11.                      THEN
  12.                         you have won
  13.                         multiply the bet amount for the winning number by 35
  14.                         display the total won from the bet
  15.                         display subtotal of amount won/lost
  16.                   ELSE 
  17.                      you have lost
  18.                      subtract the bet amount from your winnings 
  19.                      display total lost from the bet
  20.                      display subtotal of amount won/lost
  21.           END IF
  22.         END WHILE
  23.          display the total winnings/losses from each bet
  24.    END IF
  25. END*/
  26. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include<stdio.h>
  28. #include<stdlib.h>
  29. #include<time.h>
  30. int main(void)
  31. {
  32.    int betnumber, betamount, betnumber2, betamount2, betnumber3, betamount3, betnumber4, betamount4;/*initialising the inputs the user can input*/
  33.    int payout, number, winnings, counter, subtotal, a, b, c, d;/*initialising the variables used in the code*/
  34.       scanf("%d %d %d %d %d %d %d %d", &betnumber, &betamount, &betnumber2, &betamount2, &betnumber3, &betamount3, &betnumber4, &betamount4);/*scanning the users inputs*/
  35.        if(betnumber<0, betnumber>37, betnumber2<0, betnumber2>37, betnumber3<0, betnumber3>37, betnumber4<0, betnumber4>37, betamount<0, betamount2<0, betamount3<0, betamount4<0, !betnumber, !betnumber2, !betnumber3, !betnumber4, !betamount, !betamount2, !betamount3, !betamount4){/*error checking to see if the bet numbers comply with the rules of the game of roulette*/
  36.             printf("please enter four bet numbers (between and including 0 and 37(37 is double zero)) and four bet amounts with a space between them i.e 1 10 2 20 3 30 4 40 ( double zero is allowed for a bet number)");/*error message stating how to input numbers*/
  37.                return(0);}
  38.             else{       
  39.                  int totalwinnings[4];/* initialising array with 4 elements for the total winnings*/
  40.                  int betnumbers[4]={betnumber, betnumber2, betnumber3, betnumber4};/* initialises array with 4 elements for bet numbers  */
  41.                  int betamounts[4]={betamount, betamount2, betamount3, betamount4}; /* initialises array with 4 elements for bet amounts */
  42.                 {winnings= 0; /* sets the winnings for each bet at 0 so that totals can be made and negative numbers from losing can occur*/
  43.                  counter=0; /* sets the counter at 0*/
  44.                  a=0; /*sets a at 0 so that the winnings and losings are stored in the correct place in the array*/
  45.                  c=0;/*sets c at 0 so that the correct bet numbers are used when recalling them from the array*/
  46.                  d=0;/*sets d at 0 so the correct bet amounts are used when recalling them from the array*/
  47.                  srand(time(0));
  48.                  while(d<4){ /* while d is less than 4 it will rotate through the bet amounts for each bet*/
  49.                     while(c<4){ /* while c is less than 4 it will rotate through the bet numbers for each bet*/
  50.                        while( a<4){ /*while a is less than 4 it will allocate the total winnings to the correct part of the array for later use*/
  51.                           while(counter<4) {   /*while the value of counter is less than 4 it will run the code*/
  52.                               payout = 35*betamounts[d];
  53.                                 number = rand() %38; /* generates a random number between 0 and 36 (37 IS DOUBLE ZERO)*/
  54.                                 printf("your bet number is %d\n", betnumbers[c]); /* prints the bet number in the array for that bet*/
  55.                                 printf("the amount you have bet is: %d\n", betamounts[d]); /* prints the bet amount in the array for that bet*/
  56.                                 printf("the winning number is %d\n", number); /*prints the output of the random number generator*/
  57.                              if(betnumbers[c] == number) /*comparing the user input bet number in the array to the random generated number*/
  58.                              {
  59.                                 printf("you have won! this amount of money you have won: %d\n",payout); /* prints the message and applies the payout calculation*/
  60.                                 totalwinnings[a]= ((payout) + (winnings)+ (betamounts[d])); /*will add the payout value and the amount that was bet to 0 and store it in the totalwinnings array*/
  61.                              }
  62.                               else if(betnumbers[c]!=number)/*if the user input bet number in the array does not equal the output of the random number generator*/
  63.                               {
  64.                                  printf("you have lost and you have lost this amount of money: %d\n", betamounts[d]);/*prints the message and the value in the bet amounts array for that bet*/
  65.                                  totalwinnings[a]=winnings-betamounts[d]; /*will subtract the betamount for that bet from winnings allowing a negative number to be used*/
  66.                               }
  67.                                 {
  68.                                if (counter==0){
  69.                                printf("subtotal for bet winnings: %d\n",  subtotal=totalwinnings[0]);/*creates a subtotal for the first bet*/               
  70.                                printf("----------------------------------------------------------------------------------- \n");
  71.                                }
  72.                                if (counter==1){
  73.                                printf("subtotal for bet winnings: %d\n", subtotal=totalwinnings[0] + totalwinnings[1]);/*creates a subtotal for the second bet*/               
  74.                                printf("----------------------------------------------------------------------------------- \n");
  75.                                }
  76.                                if (counter==2){
  77.                                printf("subtotal for bet winnings: %d\n", subtotal=totalwinnings[0] + totalwinnings[1] + totalwinnings[2]);/*creates a subtotal for the third bet*/               
  78.                                printf("----------------------------------------------------------------------------------- \n");
  79.                                }
  80.                                if (counter==3){
  81.                                printf("subtotal for bet winnings: %d\n", subtotal=totalwinnings[0] + totalwinnings[1] + totalwinnings[2] + totalwinnings[3]);/*creates a subtotal for the fourth bet*/               
  82.                                printf("----------------------------------------------------------------------------------- \n");
  83.                                }
  84.                                }
  85.                           counter++;/*will add one to counter each time this point is reached*/
  86.                           a++;/*will add one to a each time this point is reached*/
  87.                           c++;/*will add one to c each time this point is reached*/
  88.                           d++;/*will add one to d each time this points is reached*/
  89.                                             }       
  90.                                    }
  91.                  for (b=0; b<1; b++){/*this will allow us to recall the value in the array total winnings so that it will work properly*/
  92.                        printf("this is your total after 4 bets  %d \n", totalwinnings[0]+ totalwinnings[1]+totalwinnings[2]+totalwinnings[3]);/*prints the message and will add the values in each element of the array totalwinnings to create the total winnings a player has accumulated */
  93.                                     }       
  94.                  return 0;
  95.                              }          
  96.                  }
  97.               }
  98.             }
  99. }