<mosaic.cnfolio.com>
PROGRAM
  1. /* PSUEDO CODE
  2. START
  3.    GET value for Betnumber1
  4.    GET value for Betamount1
  5.    SET value for Payoutvalue1 to 0
  6.    
  7.    GET value for Betnumber2
  8.    GET value for Betamount2
  9.    SET value for Payoutvalue2 to 0 
  10.    
  11.    GET value for Betnumber3
  12.    GET value for Betamount3   
  13.    SET value for Payoutvalue3 to 0
  14.    
  15.    GET value for Betnumber4
  16.    GET value for Betamount4
  17.    SET value for Payoutvalue4 to 0
  18.    
  19.    SET value for Totalpayout to 0
  20.    SET value for Totalpayinvalue to 0
  21.    SET value for RouletteNumber to 0   
  22.  
  23. IF BetNumber1 is larger than 38
  24.    THEN
  25.       Display an error message "Please enter a valid Bet Number"
  26. END IF
  27.  
  28. IF BetAmount1 is less than or equal to 0
  29.    THEN  
  30.       Display error message "Please enter a vaild Bet Amount"
  31. END IF
  32.  
  33. IF BetNumber2 is larger than 38
  34.    THEN
  35.       Display an error message "Please enter a valid Bet Number"
  36. END IF
  37.  
  38. IF BetAmount2 is less than or equal to 0
  39.    THEN  
  40.       Display error message "Please enter a vaild Bet Amount"
  41. END IF
  42.  
  43. IF BetNumber3 is larger than 38
  44.    THEN
  45.       Display an error message "Please enter a valid Bet Number"
  46. END IF
  47.  
  48. IF BetAmount3 is less than or equal to 0
  49.    THEN  
  50.       Display error message "Please enter a vaild Bet Amount"
  51. END IF
  52.  
  53. IF BetNumber4 is larger than 38
  54.    THEN
  55.       Display an error message "Please enter a valid Bet Number"
  56. END IF
  57.  
  58. IF BetAmount4 is less than or equal to 0
  59.    THEN  
  60.       Display error message "Please enter a vaild Bet Amount"
  61. END IF
  62.  
  63. Pick random number between or including 0 and 38
  64. SET the random number to RouletteNumber
  65. IF RouletteNumber is equal to 38
  66.    THEN
  67.       Display the number as 00 with text "Winning Bet is:"
  68. END IF
  69.  
  70. IF RouletteNumber is between 0 and 38
  71.    THEN
  72.       Display the number normally with text "Winning Bet is:"
  73. END IF
  74.  
  75. IF RouletteNumber is equal to Betnumber1
  76.    THEN 
  77.       Display Betnumber1 value
  78.       Display Betamount1
  79.       Display Payoutvalue1 as Betamount1 times 35
  80.    ELSE
  81.       Display Betnumber1 value
  82.       Display Betamount1
  83.       Display Payoutvalue1 as 0
  84. END IF
  85.  
  86. IF RouletteNumber is equal to Betnumber2
  87.    THEN 
  88.       Display Betnumber2 value
  89.       Display Betamount2
  90.       Display Payoutvalue2 as Betamount2 times 35
  91.    ELSE
  92.       Display Betnumber2 value
  93.       Display Betamount2
  94.       Display Payoutvalue2 as 0
  95. END IF
  96.  
  97. IF RouletteNumber is equal to Betnumber3
  98.    THEN 
  99.       Display Betnumber3 value
  100.       Display Betamount3
  101.       Display Payoutvalue3 as Betamount3 times 35
  102.    ELSE
  103.       Display Betnumber3 value
  104.       Display Betamount3
  105.       Display Payoutvalue3 as 0
  106. END IF
  107.  
  108. IF RouletteNumber is equal to Betnumber4
  109.    THEN 
  110.       Display Betnumber4 value
  111.       Display Betamount4
  112.       Display Payoutvalue4 as Betamount4 times 35
  113.    ELSE
  114.       Display Betnumber4 value
  115.       Display Betamount4
  116.       Display Payoutvalue4 as 0
  117. END IF
  118.  
  119. Calculate TotalPayout by adding Payoutvalue1, Payoutvalue2, Payoutvalue3, and Payoutvalue4
  120. Calculate TotalPayin by adding Betamount1, Betamount2, Betamount3, and Betamount4
  121.  
  122. IF TotalPayout is more than TotalPayin
  123.    THEN
  124.       Display Payoutvalue1, Payoutvalue2, Payoutvalue3, and Payoutvalue4
  125.       Dispaly TotalPayout
  126.       Display text "Profit".
  127.    ELSE
  128.       Display Payoutvalue1, Payoutvalue2, Payoutvalue3, and Payoutvalue4
  129.       Dispaly TotalPayout
  130.       Display text "Loss".
  131. END IF
  132.  
  133. END
  134. */
  135.  
  136.  
  137. #include <stdio.h>
  138. #include <stdlib.h>
  139. #include <time.h>
  140.  
  141. int CheckingBetNumber( int );
  142. /* These are the prototypes for my functions, later used and defined in my code. */
  143. double WorkingOutTheBet( int, int, double,double );
  144. double GlobalPayout; /* This is a global variable. This is key for the information to be accessed
  145. by both the main and the function. This is used for the calcualtion. */
  146.  
  147. int main (void) {
  148.  
  149. int BetNumber1;
  150. double BetAmount1;
  151. double PayOutValue1;
  152. /* Declaring of variables */
  153.  
  154. int BetNumber2;
  155. double BetAmount2;
  156. double PayOutValue2;
  157.  
  158. int BetNumber3;
  159. double BetAmount3;
  160. double PayOutValue3;
  161.  
  162. int BetNumber4;
  163. double BetAmount4;
  164. double PayOutValue4;
  165.  
  166. double TotalPayOut = 0;
  167. double TotalPayIn = 0; /*Reseting to zero - this is used to prevent errors. */
  168. int RouletteNumber = 0;
  169. double Winnings = 0;
  170.  
  171. scanf("%d %lf",&BetNumber1, &BetAmount1); /*Scanfs used to read input values */
  172. scanf("%d %lf",&BetNumber2, &BetAmount2);
  173. scanf("%d %lf",&BetNumber3, &BetAmount3);
  174. scanf("%d %lf",&BetNumber4, &BetAmount4);
  175.  
  176. /* ERROR CHECKING - These comments are used for clarity in the code. */
  177.    CheckingBetNumber(BetNumber1);
  178.    CheckingBetNumber(BetNumber2);
  179.    CheckingBetNumber(BetNumber3);
  180.    CheckingBetNumber(BetNumber4);
  181.    
  182.   
  183. if (BetAmount1 <= 0)
  184. {  printf("\nPlease enter a valid bet amount for bet."); }
  185. /*A simple if statement is fine for this section of the error checking.
  186. It allows for the responce to be personalised for specific bets.*/
  187.  
  188. if (BetAmount2 <= 0)
  189. {  printf("\nPlease enter a valid bet amount for bet."); }
  190.  
  191. if (BetAmount3 <= 0)
  192. {  printf("\nPlease enter a valid bet amount for bet."); }
  193. /* If a function was used, this could cut some length of the code but would just be an if statements
  194. similar to 'CheckingBetNumber'. The main isssue was the name "amou nt(" as "m ount(" was a unusable name,
  195. and no suitable repacement could be found. Therefore, simple if. NOTE-Not even allowed in comments.*/
  196.  
  197. if (BetAmount4 <= 0)
  198. {  printf("\nPlease enter a valid bet amount for bet."); }
  199.  
  200.  
  201. /* ROULETTE NUMBERS */
  202. srand(time(0));
  203. RouletteNumber = rand() % 39;
  204.    switch (RouletteNumber) /* Using a Switch, instead of an if statements, as it's using only
  205.    numbers/interger values. This reduces possible errors.*/
  206.    {  case 38: printf("\nWinning bet: 00"); break;
  207.       default :
  208.       printf("\nWinning bet: %d", RouletteNumber); break; }
  209.            
  210. /* BET NUMBER 1*/
  211.    printf("\n\n--BET 1--");
  212.    WorkingOutTheBet(RouletteNumber,BetNumber1,BetAmount1,PayOutValue1);
  213.    PayOutValue1 = GlobalPayout; /*This is where the Global variable becomes used
  214.    with in main, It allows the transfer of the information from the function. This allows
  215.    for the variation of the calculation.*/
  216.          
  217. /* BET NUMBER 2*/
  218.    printf("\n\n--BET 2--");
  219.    WorkingOutTheBet(RouletteNumber,BetNumber2,BetAmount2,PayOutValue2);
  220.    PayOutValue2 = GlobalPayout;
  221.    
  222.    /* The use of functions significantly cut down the length of the code. The function allows the reduction of errors
  223.    in lengthy and repretitive code, with additions and modifications being able to be added quickly and easily to the
  224.    sections of code. Using the function I can vary the calculation by using predefined varaibes. */
  225.  
  226. /* BET NUMBER 3 */
  227.    printf("\n\n--BET 3--");
  228.    WorkingOutTheBet(RouletteNumber,BetNumber3,BetAmount3,PayOutValue3);
  229.    PayOutValue3 = GlobalPayout;
  230.  
  231. /* BET NUMBER 4 */
  232.    printf("\n\n--BET 4--");
  233.    WorkingOutTheBet(RouletteNumber,BetNumber4,BetAmount4,PayOutValue4);
  234.    PayOutValue4 = GlobalPayout;
  235.    
  236. /* CALC TOTAL */
  237.    printf("\n\n--TOTALS--");
  238.    TotalPayIn = (BetAmount1+BetAmount2+BetAmount3+BetAmount4);
  239.    printf("\n\nTotal Payin: %.2lf", TotalPayIn);
  240.  
  241.    TotalPayOut = (PayOutValue1+PayOutValue2+PayOutValue3+PayOutValue4);
  242.    printf("\nTotal Payout: %.2lf", TotalPayOut);
  243.  
  244.    Winnings = (TotalPayOut - TotalPayIn);
  245.    {  if(TotalPayIn >= TotalPayOut) /*Using the if statement to allow for a comparison.*/
  246.          printf("\nLoss of %.2lf", Winnings);
  247.       else
  248.          printf("\nProfit of %.2lf",Winnings)}
  249.  
  250.  /*END OF MAIN*/}
  251.  
  252. /* Error Checking Bet Amount Function */
  253. int CheckingBetNumber(int checkingnumber)
  254. {  /* This doesn't need to be a function, however it keep repeated tasks neat.
  255.    This was a first attempt at functions and help develop into the second function below. */
  256.    if (checkingnumber > 38)
  257.       printf("\n\nPlease enter a valid bet number.");
  258. }
  259.  
  260. /* Workingout Bet Function */
  261. double WorkingOutTheBet(int RouletteNumber,int BetNumber, double BetAmount, double PayOutValue)
  262. {  /*The functions uses generic variables, which are similar to the variable names.*/
  263.    if (RouletteNumber == BetNumber)
  264.       {  printf("\nYour Bet Number: %d. \nYour Bet Amount %.2lf", BetNumber, BetAmount);
  265.          PayOutValue = (BetAmount*35+BetAmount)
  266.          GlobalPayout = PayOutValue;
  267.  
  268.          printf("\nPayout: %.2lf. \nProfit of: %.2lf.", PayOutValue, (PayOutValue - BetAmount) );}
  269.    else
  270.       {  printf("\nYour Bet Number: %d. \nYour Bet Amount %.2lf.", BetNumber, BetAmount);
  271.          PayOutValue = 0;
  272.          GlobalPayout = PayOutValue;
  273.    /* This is where the global variable becomes useful within the function,
  274.    this allows the variable to be transfered out, and can be used in main.*/
  275.          printf("\nPayout: %.2lf. \nLoss of: -%.2lf.", PayOutValue, BetAmount); }
  276. }