<mosaic.cnfolio.com>
PROGRAM
1. /*
2. START
3.      obtain each of the 4 bets and their amounts (8 inputs)
4.   IF the number bet on is 00
5. THEN it is equal to 37
6.   IF bets are negative or amounts are zero or less
7. THEN display error message
8. END IF
9.      generate and display a random winning number (up to 37) for each bet
10.      display the number bet on for each bet, their payout ratio and their bet amount
11.   IF the number bet on is the number generated
12. THEN calculate and display the profit for each bet
13. ELSE calculate and display the loss for each bet
14. END IF
15.      calculate total profit/loss
16.   IF the total is negative
17. THEN display the total loss
18. ELSE IF the total is zero
19. THEN display there is no loss or profit
20. ELSE IF the total is positive
21. THEN display the total profit
22. END IF
23. END
24. */
25. #include <stdio.h>
26. #include <stdlib.h>
27. #include <time.h>
28. #include <string.h>
29.
30. int main( void )
31. {
32. int amnt1, amnt2, amnt3, amnt4;
33. int number1, number2, number3, number4;
34. int out1, out2, out3, out4, total;
35. int bet1= 37;
36. int bet2= 37;
37. int bet3= 37;
38. int bet4= 37;
39. char dzero[] = {"00"};
40. char bet1z;
41. char bet2z;
42. char bet3z;
43. char bet4z;
44.
45. scanf("%s %d %s %d %s %d %s %d", &bet1z, &amnt1, &bet2z, &amnt2, &bet3z, &amnt3, &bet4z, &amnt4);
46. if(strncmp(dzero, bet1z, 2)) //if bet1 is 00 it is equal to 37 so when 37 is picked from random they are equal
47. {bet1=atoi(bet1z);}
48. if(strncmp(dzero, bet2z, 2))
49. {bet2=atoi(bet2z);}
50. if(strncmp(dzero, bet3z, 2))
51. {bet3=atoi(bet3z);}
52. if(strncmp(dzero, bet4z, 2))
53. {bet4=atoi(bet4z);}
54.
55. if (bet1<0 || bet2<0 || bet3<0 || bet4<0 || amnt1<=0 || amnt2<=0 || amnt3<=0 || amnt4<=0)  //error code
56. printf("ERROR: Bets cannot be less than zero and amounts can't be zero or less\n");
57.
58. srand( time(0) );
59.
60. /*Bet 1*/
61. number1 = rand() %38; //generates winning number for bet 1
62. if (number1 ==37)
63. printf ("Bet 1\n The winning number is 00\n")//When Winning number is 00
64. else
65. printf ("Bet 1\n The winning number is %d\n", number1); // winning number
66.
67. printf (" The number you chose was %d\n", bet1)// number bet on
68.
69. printf (" You bet £%d for this bet\n", amnt1);    //amount bet on
70. printf (" The payout ratio is 35:1\n");
71. if (bet1 == number1)    //if successful
72.
73. {out1 = amnt1*35;
74. printf (" You profited £%d for this bet\n", amnt1*35);}   //profit made
75. else
76. {printf (" You lost £%d for this bet\n", amnt1)//loss made
77. out1 =-amnt1;}  //a loss therefore negative
78.
79. /*Bet 2*/
80. number2 = rand() %38; //same process as previous bet
81. if (number2 == 37)
82. printf ("Bet 2\nThe winning number is 00\n");
83. else
84. printf ("Bet 2\n The winning number is %d\n", number2);
85.
86. printf (" The number you chose was %d\n", bet2);
87.
88. printf (" You bet £%d for this bet\n", amnt2);
89. printf (" The payout ratio is 35:1\n");
90.
91. if (bet2 == number2)
92. {printf (" You profited £%d for this bet\n", amnt2*35);
93. out2 = amnt2*35;}
94. else
95. {printf (" You lost £%d for this bet\n", amnt2);
96. out2 = -amnt2;}
97.
98. /*Bet 3*/
99. number3 = rand() %38; //same process as previous bets
100. if (number3 == 37)
101. printf ("Bet 3\n The winning number is 00\n");
102. else
103. printf ("Bet 3\n The winning number is %d\n", number3);
104.
105. printf (" The number you chose was %d\n", bet3);
106.
107. printf (" You bet £%d for this bet\n", amnt3);
108. printf (" The payout ratio is 35:1\n");
109.
110. if (bet3 == number3)
111. {printf (" You profited £%d for this bet\n", amnt3*35);
112. out3 = amnt3*35;}
113. else
114. {printf (" You lost £%d for this bet\n", amnt3);
115. out3 = -amnt3;}
116.
117. /*Bet 4*/
118. number4 = rand() %38; //same process as previous bets
119. if (number4 == 37)
120. printf ("Bet 4\n The winning number is 00\n");
121. else
122. printf ("Bet 4\n The winning number is %d\n", number4);
123.
124. printf (" The number you chose was %d\n", bet4);
125.
126. printf (" You bet £%d for this bet\n", amnt4);
127. printf (" The payout ratio is 35:1\n");
128.
129. if (bet4 == number4)
130. {printf (" You profited £%d for this bet\n", amnt4*35);
131. out4 = amnt4*35;}
132. else
133. {printf (" You lost £%d for this bet\n", amnt4);
134. out4 = -amnt4;}
135.
136. /*Totals*/
137. total = out1 + out2 + out3 + out4; //total of profits combined with losses
138. if (total<0)
139. printf("You made a total loss of -£%d\n", total*-1); //displays a loss when total is -ve
140. else if (total==0)
141. printf("You neither made a loss or profit\n")//no profit or loss
142. else if (total>0)
143. printf("You made a profit of £%d\n", total); //displays a profit when total is +ve
144. }