<mosaic.cnfolio.com>
PROGRAM
  1. /* START
  2. Initialize pocket number and bet amount
  3. Initialize bet number
  4. WHILE bet number is less than 4 
  5. IF 1 of the bet numbers is more than 37
  6.   THEN Display error message and end the program
  7.     ELSE IF 1 of the bet numbers is less than 0
  8.       THEN Display error message and end the program
  9.         ELSE IF 1 of the bet amounts is less than 0
  10.          THEN Display error message and stop the program
  11.       END IF
  12.    END IF
  13. END IF
  14.  
  15. IF number1 equals 37
  16.   THEN display that the user has selected 00 and the amount of money he has bet
  17.      ELSE display user bet number and bet amount
  18. END IF
  19.  
  20. IF winnumber1 equals the users bet number
  21. THEN
  22.    Display the winning number of the first spin
  23.    Display user bet number,winning number,payout value and current wallet value
  24.      ELSE IF winning number equals 37 and user number equals 37
  25.       THEN
  26.        Display winning number 00,bet number 00,payout value and current wallet value
  27.         ELSE
  28.          Display the winning number for the first spin,user's lost bet and current wallet value
  29.     END IF
  30. END IF
  31. END WHILE
  32. Display  Total profit/loss for the user
  33. Display total money from won bets
  34. Display total money for lost bets
  35. IF  total earning are less or equal to 0
  36.    THEN
  37.    Display total earnings as 0
  38.    ESLE
  39.    Display total earnings
  40. END IF
  41. END
  42. */
  43. #include<stdio.h>
  44. #include<ctype.h>
  45.  
  46. int main()
  47. {
  48. int i; /* This is so the for loop works with 4 bets and arrays */
  49. int number[4];
  50. float bet[4] = {0}; /* the array is set to 0 for error checks,incase the users inputs a letter or symbol */
  51. int winnumber[4];
  52. float winmoney[4]={0};
  53. float lostbet[4]={0};
  54. float totalwin = 0 ;
  55. float totalloss = 0 ;
  56. float totalearnings= 0 ;
  57. float wallet ;
  58.  
  59. printf("Welcome to american roulette. \n");
  60.  
  61. printf("Please place your bets. \n");
  62.  
  63. if((scanf( "%d %f %d %f %d %f %d %f", &number[0], &bet[0],&number[1],&bet[1],&number[2],&bet[2],&number[3],&bet[3])) != 8)
  64. {
  65. printf("Error: Not enough bets. \n");
  66. return 0;
  67. }
  68.  
  69. for ( i = 0; i<4 ; i++)
  70. {
  71. if ( number[i] > 37 )
  72. {
  73. printf( " Error: Please select a number to bet on between 0-37, 37 being 00. \n");
  74. return 0;
  75. }
  76. else if( number[i] < 0 )
  77. {
  78. printf( " Error: Please select a number to bet on between 0-37, 37 being 00. \n");
  79. return 0;
  80. }
  81.  
  82. else if ( bet[i] <=0  )
  83. {
  84. printf ( "Error: You haven't bet anything on one of the numbers.\n");
  85. return 0;
  86. }
  87.  
  88.  
  89. srand(time(0));
  90. winnumber[0] = rand() % 38; /* its set from 0 to 37 so that it can account for the 00*/
  91. winnumber[1] = rand() % 38;
  92. winnumber[2] = rand() % 38;
  93. winnumber[3] = rand() % 38;
  94.  
  95.  
  96. printf("      BET %d     \n",i +1);
  97.  
  98. if ( number[i] == 37)
  99. {printf("You have selected number 00 and placed %0.2f on it.\n",bet[i]);}
  100. else
  101. {
  102. printf("You have selected number %d and placed %0.2f on it.\n", number[i],bet[i]);
  103. }
  104.  
  105.  
  106.  
  107. if (winnumber[i] == number[i])
  108. {
  109. printf("The winning number in this spin is %d. \n",winnumber[i]);
  110. winmoney[i] =bet[i] + bet[i]*35;
  111. wallet = wallet + winmoney[i];
  112. printf("For your bet, you placed a bet on number %d and won %0.2lf . \n ", winnumber[i],winmoney[i]);
  113. printf(" Current wallet: %0.2lf . \n",wallet);
  114. }
  115.  
  116.  
  117.  
  118. else if ( winnumber[i] == 37 && number[i] == 37 ) /* This so that can bet on 00 */
  119. {
  120. printf("The winning number on the firts spin is 00. \n");
  121. winmoney[i] =bet[i] + bet[i]*35;
  122. wallet= wallet + winmoney[i];
  123. printf("For your  bet, you placed a bet on number 00 and won %0.2lf . \n ",winmoney[i]);
  124. printf(" Current wallet: %0.2lf . \n",wallet);
  125. }
  126.  
  127.  
  128.  
  129. else
  130. {
  131. printf("The winning number in this spin is %d. \n",winnumber[i]);
  132. lostbet[i] = bet[i];
  133. wallet = wallet - lostbet[i];
  134. printf("You lost your bet of %0.2lf on number %d. \n",bet[i],number[i]);
  135. if ( wallet <= 0 )
  136. {printf(" Current wallet: 0 . \n");}
  137. else
  138. {
  139. printf(" Current wallet: %0.2lf . \n",wallet);
  140. }
  141. }
  142. }
  143.  
  144. printf("    TOTAL PROFIT/LOSS     \n");
  145.  
  146. totalwin = winmoney[0] + winmoney[1] + winmoney[2] + winmoney[3];
  147. printf("Total profit: %0.2lf \n",totalwin );
  148.  
  149. totalloss = lostbet[0] + lostbet[1] + lostbet[2] +lostbet[3];
  150. printf("Total loss: %0.2lf \n",totalloss);
  151.  
  152. totalearnings = totalwin - totalloss;
  153. if (totalearnings <= 0) /* You cant take more than the player already has bet*/
  154. {printf("Total Earnings: 0.00 \n");}
  155. else
  156. {printf("Total Earnings: %0.2lf \n",totalearnings);}
  157. }