<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. START
  3.  
  4. SET purse to 100
  5. SET i to 1
  6.  
  7. WHILE 'i' is less than 5
  8.  
  9. -INPUTS-
  10.  
  11. input bet amount equals: (GET player input for bet amount)
  12. round bet amount to two decimal places
  13.  
  14. GET both characters for bet number
  15.  
  16. IF first character equals 0 AND second character equals 0
  17.    
  18.    THEN
  19.    set bet number to 37
  20.    set input bet number to 1
  21.  
  22. ELSE
  23. convert array to interger and store in bet amount
  24. IF bet number equals 37
  25.    
  26.    THEN
  27.    display error message saying to pick a number between 0 and 36 or 00
  28.  
  29. END IF
  30.  
  31. -ERROR MESSAGES-
  32.  
  33. IF input bet number equals 1 OR input bet amount equals 1
  34.    
  35.    THEN
  36.    display error message telling player to input the required inputs
  37.    end program
  38.    
  39. END IF
  40.  
  41. IF bet amount is less than 0 OR bet amount is more than 37
  42.  
  43.    THEN
  44.    display error message telling them to input something in between 0 and 36 or 00
  45.    end program
  46.    
  47. END IF
  48.  
  49. IF betamount is less than or equal to 0
  50.  
  51.    THEN
  52.    display error message saying they need to input a bet amount higher than 0
  53.    end program
  54.    
  55. END IF
  56.  
  57. -PURSE CHECK-
  58.  
  59. purse check equals purse minus the bet amount
  60.  
  61. IF purse check is less than 0
  62.  
  63.    THEN
  64.    display error message saying that the player doesnt have the required funds to make the bet
  65.    end program
  66.  
  67. END IF
  68.  
  69. - MAIN GAME CODE -
  70.  
  71. generate a random number
  72. calculate the winning payout value multiplier
  73.  
  74. set winning number to the randomly generated number
  75.  
  76. SWITCH bet number
  77.  
  78. CASE when bet number equals 37
  79.  
  80.    IF winning number equals 37
  81.  
  82.       THEN
  83.       display the player has won on number 00
  84.       calculate the winnings depending on the bet amount bet
  85.       add winning to the purse
  86.       display new purse
  87.  
  88.    ELSE
  89.       IF winning number does not equal 37
  90.  
  91.          THEN
  92.          diplay the winnning number and the bet number aswell as that the player had lost the bet
  93.          minus the bet amount from the purse
  94.          display the new purse value 
  95.  
  96.    END IF
  97.  
  98. END SWITCH
  99.  
  100. CASE default
  101.  
  102.    IF winning number equals bet number
  103.  
  104.       THEN
  105.       display the player has won in the winning number
  106.       calculate the winnings depending on the bet amount bet
  107.       add winning to the purse
  108.       display new purse
  109.  
  110.    ELSE
  111.       IF winning number does not equal the bet number
  112.  
  113.          THEN
  114.          diplay the winnning number and the bet number aswell as that the player had lost the bet
  115.          minus the bet amount from the purse
  116.          display the new purse value 
  117.  
  118.    END IF
  119.  
  120. END SWITCH
  121.  
  122. add i one to the i interger
  123.  
  124. END WHILE
  125.  
  126. display final purse value
  127. diaply final profit loss value
  128.  
  129. END
  130. */
  131.  
  132. #include <stdio.h>
  133. #include <math.h>
  134. #include <time.h>
  135. #include <stdlib.h>
  136.  
  137. int main (void)
  138. {
  139. char betnum [1] = {'\0'};
  140.  
  141. float winnings;
  142. float wincalc;
  143. float betamount;
  144. float betamounttwo;
  145. float purse;
  146.  
  147. int pursecheck;
  148. int inputbetnum;
  149. int inputbetamount;
  150. int doublezero;
  151. int betnumber;
  152. int i;
  153. int winningnumber;
  154.  
  155.  
  156. purse = 100;
  157. i = 1;
  158.  
  159. /* WHILE LOOPS ALLOWS FOR THE PROGRAM TO GET 4 SETS OF TWO INPUTS FROM THE PLAYER, SIMULATING 4 BETS */
  160.  
  161. while  (i < 5)
  162. {
  163. /* GET THE REQUIRED INPUTS FROM THE PLAYER (8 INPUTS IN TOTAL, A BET AMOUNT FOLLOWED BY A BET NUMBER) */
  164.  
  165. inputbetamount = scanf ("%f", &betamount);
  166. betamounttwo = floorf(betamount*100)/100; /* INITIALLY THIS WAS NOT NEEDED, BUT A SMALL AMOUNT WAS READ ADDED TO WHOLE NUMBERS FOR
  167.                                              SOME REASON. BECAUSE OF THIS WHEN THE PLAYER HAD 0 MONEY LEFT IT WOULD READ IT AS A
  168.                                              SMALL NEGATIVE NUMBER. THIS LINE MAKES THE NUMBER TRUE TO TWO DP. */
  169.  
  170. scanf ("%*c%c", &betnum[0]);
  171. scanf ("%c", &betnum[1]);
  172.  
  173. if (betnum[0] == '0' && betnum[1] == '0')
  174. {betnumber = 37;  inputbetnum = 1;}
  175.  
  176. else
  177. {
  178. inputbetnum = sscanf (betnum, "%d",&betnumber);
  179. if (betnumber == 37)
  180. {printf ("\nError in number set %d. Type in a number inbetween 0 and 36 or 00.\n", i);
  181. return 0;}
  182. }
  183.  
  184.  
  185. /* RUNNING ALL ERROR MESSAGES */
  186.  
  187. if (inputbetnum != 1 || inputbetamount != 1)
  188. {
  189. printf ("\nError in number set %d. \nPlease input a positive bet amount, followed by the bet number.\nAll seperated by single spaces. Bet four times.\n", i);
  190. return 0;
  191. }
  192.  
  193. if (betnumber < 0 || betnumber > 37)
  194. {
  195. printf ("\nError in number set %d. Please type in a number inbetween 0 and 36 or 00.\n", i);
  196. return 0;
  197. }
  198.  
  199. if (betamounttwo <= 0)
  200. {
  201. printf ("\nError in number set %d. You have zero or less bet placed, please place a positive bet.\n", i);
  202. return 0;
  203. }
  204.  
  205. /* CHECK IF THE BET PLACED ISNT MORE THAN WHAT YOU HAVE IN PURSE*/
  206.  
  207. pursecheck = purse - betamounttwo;
  208. if (pursecheck < 0)
  209. {
  210. printf ("\nmake sure you have enough money in your purse to make that bet. you start with 100, keep that in mind.\n");
  211. return 0;
  212. }
  213. /* RANDOM NUMBER GENERATOR */
  214.  
  215. srand (time(NULL));
  216.  
  217. /* WINNINGS FORMULA */
  218.  
  219. wincalc = ((36/1)-1); /* CALCULATES THE WIN TOTAL/ RETURN */
  220.  
  221. /* MAIN GAME OPERATION */
  222.  
  223. sleep (1); /* ADDS A ONE SECOND DELAY TO MAKE SURE A DIFFERENT VALUE FOR WINNING NUMBER IS SELECTED AS ITS DEPENDANT ON TIME. */
  224. winningnumber = rand () % 37;
  225.  
  226.  
  227. switch (betnumber)
  228. {
  229. default:
  230. {
  231. if (winningnumber == betnumber)
  232. {
  233. winnings = wincalc * betamount;
  234. printf ("\ncongratulations!! your number %d won!, youve won %.2f.\n", betnumber, winnings);
  235. purse = purse + winnings;
  236. printf ("your new purse is %.2f.\n",purse);
  237. }
  238. else
  239.  
  240. if (winningnumber != betnumber)
  241. {
  242. printf ("\nsorry the number the ball landed on was %d, you bet %.2f on number %d. better luck next time.\n", winningnumber, betamount, betnumber);
  243. purse = purse - betamount;
  244. printf ("your loss/profit for this round is = %.2f\n",-betamount);
  245. printf ("\nyour new purse is %.2f.\n",purse);
  246. }
  247. break;
  248. }
  249.  
  250. case 37:
  251. {
  252. if (winningnumber == 37)
  253. {
  254. winnings = wincalc * betamount;
  255. printf ("\ncongratulations!! your number 00 won!, youve won %.2f.\n", winnings);
  256. purse = purse + winnings;
  257. printf ("your new purse is %.2f.\n",purse);
  258. }
  259.  
  260. else
  261.  
  262. if (winningnumber != 37)
  263. {
  264. printf ("\nsorry the number the ball landed on was %d, you bet %.2f on number 00. better luck next time.\n", winningnumber, betamount);
  265. purse = purse - betamount;
  266. printf ("your loss/profit for this round is = %.2f\n",-betamount);
  267. printf ("\nyour new purse is %.2f.\n",purse);
  268. }
  269. break;
  270. }
  271. }
  272.  
  273. i++; /* < THIS ADDS ONE TO i SO THAT THE LOOP WILL END AFTER 4 CYCLES*/
  274. }
  275. printf ("\nfinal purse: %.2f", purse);
  276. printf ("\nyour final loss/profit is: %.2f", (purse - 100));
  277. }