<mosaic.cnfolio.com>
PROGRAM
1. #include <stdio.h>
2. #include <string.h>
3. #include <stdlib.h>
4. #include <time.h>
5. int main(void)
6. {
7. char number[3] = {0};
8. char *doublezero = "00";                                                        //Declare number 00
9. int  comparison;
10. int  betnumber[5] = {0};
11. int  bet[5] = {0};
12. int  winnumber = {0};
13. int  count = {0};
14. int  winningmoney[5] = {0};
15. int  lossingmoney[5] = {0};
16. int  payout = {0};
17. int  profit = {0};
18. int  loss = {0};
19. int  total = {0};
20.
21. for(int i=1; i<5; ++i)
22. {
23. scanf("%s", number);
24. comparison = strncmp(number, doublezero, 2);                                  //Determine if the input number is 00
25. if (comparison == 0){ //if there is a 00 in input
26. betnumber[i] = 37;                                                           //The output is 37
27. printf("Your bet number[%d] is %s,", i, doublezero);                        //Show 00 in the output
28. }
29. else{
30. betnumber[i] = atoi(number);                                                 //Scan input numbers
31. printf("Your bet number[%d] is %d.", i, betnumber[i]);
32. if(betnumber[i] < 0 || betnumber[i] > 36){
33. printf("Input error,please input the bet[%d] number again:\n", i)
34.    }
35.  }                                                                    //Display error for wrong input values
36.
37. scanf("%d", &bet[i]);//scan input
38. printf("the money amount the of bet[%d] is %d;\n", i, bet[i]);      //Display money amount for each bet
39. if (bet<0)
40. {
41. printf("input error,please input out again:\n");                   //Dsiplay error for wrong input valuse
42.
43.  }
44. }
45.
46. srand(time(NULL));    //use rand() function to generate 4 random numbers
47. int winnumber1=rand()%37;
48. int winnumber2=rand()%37;
49. int winnumber3=rand()%37;
50. int winnumber4=rand()%37;
51. if(winnumber==37){
52. printf("winner number is %s\n", doublezero);   //if there is a 37 in the random numbers,display 00 in the output
53. }
54. else{
55. printf("winner numbers are %d,%d,%d,%d\n", winnumber1,winnumber2,winnumber3,winnumber4);
56. }//display the random winning numbers
57. for(int i=1; i<5;  ++i){
58. count=(winnumber-betnumber[i]);
59. if(count==0){
60. printf("winner! ");// if the random winnumber eqaul to the input bet number, display winner
61. winningmoney[i]=(bet[i]*35);
62. printf("winning money of bet[%d] is %d\n", i, winningmoney[i]);//calculate and display the winning money amount
63. }
64. else{
65. printf("You lose!");
66. lossingmoney[i]=bet[i];
67. printf("lossing money of bet[%d] is %d\n", i, lossingmoney[i]);//calculate and display the lossing money amount
68.  }
69. }
70. payout=(bet[1]+bet[2]+bet[3]+bet[4]);//calculate payout
71. profit=(winningmoney[1]+winningmoney[2]+winningmoney[3]+winningmoney[4]);//calculate the profit
72. loss=(lossingmoney[1]+lossingmoney[2]+lossingmoney[3]+lossingmoney[4]);//calculate the loss
73. total=(profit-loss);//calculate total money letf in the end
74. printf("payout is %d\n", payout);//display payout
75. printf("profit is %d\n", profit);//display profit
76. printf("loss is %d\n", loss);//display loss
77. printf("total money is %d\n", total);//display total
78.
79. }