<mosaic.cnfolio.com>
PROGRAM
  1. /* Pseudocode
  2.  
  3. START
  4. get all 4 bets and bet amounts,
  5. the current bet becomes the first one,
  6.  
  7. WHILE counter < 4,
  8.   choose a random number between 00 and 36,
  9.  
  10.   IF that number is the same as the current bet number,
  11.      display the bet number, bet amount, the winning number, 35 times your bet amount + your bet amount, and 35 times your bet amount,
  12.      add 35 times your bet amount to 'total',
  13.      add your bet amount to 'total',
  14.   ELSE
  15.      display the bet number, bet amount, the winning number, 0, and the negative of your bet,
  16.      subtract your bet from 'total',
  17.   ENDIF
  18.  
  19. add 1 to 'counter',
  20. the current bet becomes the next one along,
  21. ENDWHILE
  22.  
  23. display 'total'
  24. END
  25.  
  26. */
  27.  
  28. /*error messages for alphabetical and negative needed*/
  29.  
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <time.h>
  33.  
  34. int main ( void ){
  35.  
  36. char FirstDigit[4] = {'\0','1','2','3'}/*arrays for the two chars that make up the numbers between 00 and 36*/
  37. char SecondDigit[10] = {'0','1','2','3','4','5','6','7','8','9'};
  38.  
  39. int Ball;
  40. int BallTens;
  41. int BallUnits;
  42. char FirstRandom = '0' ;
  43. char SecondRandom = '0' ;
  44.  
  45. char BetA[3] = { '\0' };   /*5 strings for each bet number, and a temporary variable*/
  46. char BetB[3] = { '\0' };
  47. char BetC[3] = { '\0' };
  48. char BetD[3] = { '\0' };
  49. char BetN[3] = { '\0' };
  50.  
  51. int MoneyA;
  52. int MoneyB;
  53. int MoneyC;
  54. int MoneyD;
  55. int MoneyN;
  56.  
  57. int counter = 0;
  58. int Othercounter = 0;
  59. int total = 0;
  60. char halt = 'h';
  61.  
  62. if (scanf ("%s %d %s %d %s %d %s %d", BetA, &MoneyA, BetB, &MoneyB, BetC, &MoneyC, BetD, &MoneyD) < 8)/*number of inputs checked*/
  63.    printf("Err: missing value(s)!");
  64.  
  65. else if ((MoneyA <= 0) || (MoneyB <= 0) || (MoneyC <= 0) || (MoneyD <= 0))/*money error checking*/
  66.    printf("Err: Money entered is 0 or negative!");
  67.  
  68. else{
  69.    
  70.    /*while ((counter < 4) && (halt = 'h')){
  71.    
  72.    halt = 'H';
  73.    switch (counter){ 
  74.    
  75.       case 0: BetN[0] = BetA[0];
  76.       BetN[1] = BetA[1];
  77.       break;
  78.      
  79.       case 1: BetN[0] = BetB[0];
  80.       BetN[1] = BetB[1];
  81.       break;
  82.      
  83.       case 2: BetN[0] = BetC[0];
  84.       BetN[1] = BetC[1];
  85.       break;
  86.      
  87.       case 3: BetN[0] = BetD[0];
  88.       BetN[1] = BetD[1];
  89.       break;     
  90.      
  91.   }
  92.    Othercounter =0;
  93.    do{
  94.       if (BetN[0] == FirstDigit[Othercounter])
  95.          halt = 'h';
  96.          Othercounter++;
  97.    }while ((Othercounter != 4) && (halt = 'H'));
  98.    
  99.    Othercounter =0;
  100.    do{
  101.       if (BetN[1] == SecondDigit[Othercounter])
  102.          halt = 'h';
  103.          Othercounter++;
  104.    }while ((Othercounter != 10) && (halt = 'H'));
  105.    
  106.    counter++;
  107.   }
  108.  
  109.   if (halt = 'h'){*/
  110.  
  111.   srand(time(0))/*initializing the rand function*/
  112.   counter = 0;
  113.   while (counter < 4){
  114.    
  115.     switch (counter){   /*temporary variables becomes the relevant bet/money*/
  116.      
  117.       case 0: BetN[0] = BetA[0];
  118.       BetN[1] = BetA[1];
  119.       MoneyN = MoneyA;
  120.       break;
  121.      
  122.       case 1: BetN[0] = BetB[0];
  123.       BetN[1] = BetB[1];
  124.       MoneyN = MoneyB;
  125.       break;
  126.      
  127.       case 2: BetN[0] = BetC[0];
  128.       BetN[1] = BetC[1];
  129.       MoneyN = MoneyC;
  130.       break;
  131.      
  132.       case 3: BetN[0] = BetD[0];
  133.       BetN[1] = BetD[1];
  134.       MoneyN = MoneyD;
  135.       break;     
  136.      
  137.     }
  138.    
  139.     Ball = rand() %38/*number is randomly chosen here*/
  140.     BallTens = Ball/10;
  141.     BallUnits = Ball %10;
  142.    
  143.     if ((BallUnits == 0) && (BallTens == 0)){/*for the sake of things looking nicer, only 00 has a leading 0*/
  144.       FirstRandom = '0';
  145.       SecondRandom = '0';
  146.     }
  147.     else{
  148.       FirstRandom = FirstDigit[BallTens];
  149.       SecondRandom = SecondDigit[BallUnits];    
  150.      
  151.     }
  152.    
  153.     if ( (BetN[0] == FirstRandom) && (BetN[1] == SecondRandom) ){ /*only winning condition is when bet chars match the random chars*/
  154.      
  155.       printf("Your bet and money placed were: %c%c and $%d, the winning number was: %c%c, your payout and profit were: $%d and $%d\n", BetN[0], BetN[1], MoneyN,  FirstRandom, SecondRandom, (36 * MoneyN), (35 * MoneyN));
  156.       total = total + (36 * MoneyN);
  157.      
  158.     }
  159.     else{
  160.      
  161.       printf("Your bet and money placed were: %c%c and $%d, the winning number was: %c%c. The payout was $0, and your loss is $%d.\n", BetN[0], BetN[1], MoneyN, FirstRandom, SecondRandom, (-1 * MoneyN));
  162.       total = total - MoneyN;
  163.      
  164.     }
  165.     counter++; /*the process happens once for each bet*/
  166.    
  167.   }
  168.   printf("$%d is your total profit/loss", total)/*currency is dollars, because US roulette*/
  169.  
  170.   }
  171.  
  172.    /*else
  173.    printf("Alphabetical input!");
  174.    }*/
  175. }