<mosaic.cnfolio.com>
PROGRAM
  1. /*START
  2.  
  3.    SET bet numbers to 37 and bet values to 0
  4.    SET net wins and losses to 0
  5.    
  6.    SCAN all 8 input numbers
  7.    
  8.     IF no or insufficient inputs and/or bets are set out of 0-36 range or 00
  9.      
  10.      THEN
  11.       Display error message: "ERROR! Please bet something!"
  12.       Display error message: "ERROR! Bet number out of range!"
  13.    
  14.      ELSE
  15.       Continue with the program
  16.    
  17.     ENDIF
  18.    
  19.    Randomly generate any 4 numbers within range
  20.    
  21.    Display player's betting numbers, winning numbers and payout for each bet
  22.      
  23.     IF the bet by the player respectively matches the random generated number (first bet matches first generated number and so on)
  24.      
  25.      THEN
  26.       Display a congratulations message with the winning profit
  27.      
  28.      ELSE
  29.       Display an unlucky message with the player losses
  30.    
  31.     ENDIF
  32.    
  33.    Repeat the displays for all 4 bets
  34.    
  35.    At the end of all bets, display profits (if any) in pounds()
  36.    
  37.     IF the player won more money than lost
  38.    
  39.      THEN
  40.       Display a congratulatory message with the total profit for all bets
  41.      
  42.      ELSE
  43.       Display a message with the player's total losses for all bets
  44.      
  45.     ENDIF
  46.    
  47.    End program
  48.    
  49. END*/
  50.  
  51. #include <stdio.h>
  52. #include <time.h>
  53. #include <string.h>
  54.  
  55. int main ()
  56. {
  57.  
  58.  int counter;
  59.  int rollNumb1, rollNumb2, rollNumb3, rollNumb4;
  60.  int betNumb1=37;
  61.  float betVal1=0;
  62.  int betNumb2=37;
  63.  float betVal2=0;
  64.  int betNumb3=37;
  65.  float betVal3=0;
  66.  int betNumb4=37;
  67.  float betVal4=0;
  68.  char bet1z[2]; /*The following four statements are used so that the player can input a 00 in any of his/her bets*/
  69.  char bet2z[2];
  70.  char bet3z[2];
  71.  char bet4z[2];
  72.  char doubz[]="00";
  73.  double payout1;
  74.  float netWins1=0;
  75.  float netLoss1=0;
  76.  float netWins2=0;
  77.  float netLoss2=0;
  78.  float netWins3=0;
  79.  float netLoss3=0;
  80.  float netWins4=0;
  81.  float netLoss4=0;
  82.  double totalWins=0;
  83.  double totalLosses=0;
  84.  double totalMoney;
  85.  
  86.  scanf("%s %f %s %f %s %f %s %f", &bet1z, &betVal1, &bet2z, &betVal2, &bet3z, &betVal3, &bet4z, &betVal4);
  87.  
  88.  if(strncmp(doubz,bet1z,2)) /*The following statements were used so that the user could input a double zero as his/her bet */
  89.   {
  90.    betNumb1=atoi(bet1z);
  91.   }
  92.  
  93.  if(strncmp(doubz,bet2z,2))
  94.   {
  95.    betNumb2=atoi(bet2z);
  96.   }
  97.  
  98.  if(strncmp(doubz,bet3z,2))
  99.   {
  100.    betNumb3=atoi(bet3z);
  101.   }
  102.  
  103.  if(strncmp(doubz,bet4z,2))
  104.   {
  105.    betNumb4=atoi(bet4z);
  106.   }
  107.  
  108.  payout1 = betVal1+35*betVal1;
  109.  
  110.  srand(time(0)*time(0)*time(0)); /*I'm using time(0) cubed to create a more random output, since I noticed that if I just use one time(0) and run the program fast enough, it goes down by 2, making it more predictable*/
  111.  
  112.  rollNumb1=rand()%(38); /*This means that the random values go from 0 (which is on the board) to 37 (which represents the '00')*/
  113.  
  114.  rollNumb2=rand()%(38);
  115.  
  116.  rollNumb3=rand()%(38);
  117.  
  118.  rollNumb4=rand()%(38);
  119.  
  120.  counter = 0;
  121.  
  122.   if (betVal1<=0||betVal2<=0||betVal3<=0||betVal4<=0) /*Error message displayed when no inputs or no bet money input*/
  123.    {
  124.     printf("ERROR! Please bet something!\n");
  125.     return 0;
  126.    }
  127.  
  128.   if (betNumb1>37||betNumb2>37||betNumb3>37||betNumb4>37)
  129.    {
  130.     printf("ERROR! Bet number out of range!\n"); /*Error message displayed when player tries to input any value outside of the 0-36 range and 00*/
  131.     return 0;
  132.    }
  133.    
  134.   if (betNumb1<0||betNumb2<0||betNumb3<0||betNumb4<0)
  135.    {
  136.     printf("ERROR! Bet number out of range!\n"); /*Error message displayed when player tries to input any negative value*/
  137.     return 0;
  138.    }
  139.  
  140.   printf("Your bets are, respectively, on: %s, %s, %s and %s\n", bet1z, bet2z, bet3z, bet4z);
  141.   printf("The winning numbers are respectively: ");
  142.  
  143.   if(rollNumb1!=37) /* "Manual" way to display a 00 whenever a 37 is rolled */
  144.    {
  145.     printf("%d, ", rollNumb1);
  146.    }
  147.    
  148.   else
  149.    {
  150.     printf("00, ");
  151.    }
  152.    
  153.    if(rollNumb2!=37)
  154.    {
  155.     printf("%d, ", rollNumb2);
  156.    }
  157.    
  158.   else
  159.    {
  160.     printf("00, ");
  161.    }
  162.    
  163.    if(rollNumb3!=37)
  164.    {
  165.     printf("%d, ", rollNumb3);
  166.    }
  167.    
  168.   else
  169.    {
  170.     printf("00, ");
  171.    }
  172.    
  173.    if(rollNumb4!=37)
  174.    {
  175.     printf("and %d\n", rollNumb4);
  176.    }
  177.    
  178.   else
  179.    {
  180.     printf("and 00\n");
  181.    }
  182.  
  183.   printf("Payout for each bet is 35 to 1 (35 times your bet plus your bet).\n");
  184.  
  185.   if (betNumb1!=rollNumb1)
  186.    {
  187.     netLoss1=betVal1;
  188.     netWins1 = 0; /*If the player loses, the loss is equal to the bet number and he/she wins 0*/
  189.     printf("You lost your first bet. Lost %.2f.\n", betVal1);
  190.    }
  191.   else
  192.    {
  193.     netWins1 = 35*betVal1;
  194.     netLoss1=0;
  195.     printf("You won your first bet! Congratulations, you won a %.2f profit!\n", netWins1);
  196.    }
  197.  
  198.   if (betNumb2!=rollNumb2)
  199.    {
  200.     netLoss2=betVal2;
  201.     netWins2 = 0;
  202.     printf("You lost your second bet. Lost %.2f.\n", betVal2);
  203.    }
  204.   else
  205.    {
  206.     netWins2 = 35*betVal2;
  207.     netLoss2=0;
  208.     printf("You won your second bet! Congratulations, you won a %.2f profit!\n", netWins2);
  209.    }
  210.    
  211.    if (betNumb3!=rollNumb3)
  212.    {
  213.     netLoss3=betVal3;
  214.     netWins3 = 0;
  215.     printf("You lost your third bet. Lost %.2f.\n", betVal3);
  216.    }
  217.   else
  218.    {
  219.     netWins3 = 35*betVal3;
  220.     netLoss3=0;
  221.     printf("You won your third bet! Congratulations, you won a %.2f profit!\n", netWins3);
  222.    }
  223.  
  224.   if (betNumb4!=rollNumb4)
  225.    {
  226.     netLoss4=betVal4;
  227.     netWins4=0;
  228.     printf("You lost your fourth bet. Lost %.2f.\n", betVal4);
  229.    }
  230.   else
  231.    {
  232.     netWins4 = 35*betVal4;
  233.     netLoss4=0;
  234.     printf("You won your fourth bet! Congratulations, you won a %.2f profit!\n", netWins4);
  235.    }
  236.    
  237.   totalLosses=netLoss1+netLoss2+netLoss3+netLoss4;
  238.  
  239.   totalWins=netWins1+netWins2+netWins3+netWins4;
  240.  
  241.   totalMoney=totalWins-totalLosses;
  242.  
  243.   if (totalLosses>totalWins)
  244.    {
  245.     printf("You lost %.2f total...bad luck!\n", -totalMoney); /*Negative sign so that the total money (in the case of a complete loss) is displayed positively*/
  246.    }
  247.    
  248.   else
  249.    {
  250.     printf("Congratulations! You won a total profit of %.2f\n", totalMoney);
  251.    }
  252.  
  253.    return 0; /*return to 0 so that the player can repeat his/her bets without the previous outcomes*/
  254. }