<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. START
  3.    Get 4 bets
  4.    Get 4 amounts
  5.    Display bets
  6.    Display amounts
  7.    
  8.    Get random number between 0 and 37
  9.    IF random number is equal to 37
  10.       THEN
  11.          Display "00"
  12.       ELSE
  13.          Display random number
  14.    END IF
  15.    
  16.    WHILE "i" variable is less than 4
  17.       IF amounts is less then 0
  18.          THEN display error message
  19.       END IF
  20.      
  21.       IF bet is less than 0 OR greater than 37 OR nothing is entered
  22.          THEN
  23.             display error messsage
  24.          ELSE
  25.             IF bet is equal to winning number
  26.                THEN
  27.                   Display winning message
  28.                   Winnings is equal to amount times 35
  29.                   Losses is equal to 0
  30.                ELSE
  31.                   Dislpay lossing message
  32.                   Winnings is equal to 0
  33.                   Losses is equal to amount
  34.             END IF
  35.        END IF
  36.       Increase "i" variable value by 1
  37.    END WHILE
  38.    
  39.    Calculate total winnings
  40.    Calculate total losses
  41.    
  42.    IF total winnings minus total losses is greater than 0
  43.       THEN
  44.          Calculate wallet value
  45.          Display wallet value
  46.          Dsplay profit
  47.       ELSE
  48.          Display wallet value as 0
  49.          Display losses
  50.    END IF
  51.  
  52. END
  53. */
  54. #include <stdio.h>
  55. #include <string.h>
  56. #include <stdlib.h>
  57. #include <time.h>
  58.  
  59. int main (void)
  60. {
  61.  
  62. /*Variables*/
  63. int board[4][2];
  64. int bet[4];
  65. float money[4];
  66. int winningnum;
  67. int ret[4];
  68. char str1[20];
  69. int i = 0;
  70. float winnings[4], losses[4];
  71. float Twin, Tloss, wallet;
  72.  
  73. scanf("%s %f %s %f %s %f %s %f", &board[0], &money[0], &board[1], &money[1], &board[2], &money[2], &board[3], &money[3]); //allows for bet and money inputs
  74. printf("Bets: \n%.2f on No.%s\n%.2f on No.%s\n%.2f on No.%s\n%.2f on No.%s\n", money[0], board[0], money[1], board[1], money[2], board[2], money[3], board[3]);
  75. printf("--------------------\n");// seperater
  76.  
  77. srand(time(NULL)); winningnum = rand () % 38; // generates random number from 0 to 37
  78.  
  79.    if (winningnum == 37) {printf("Winning number: 00\n");} //display 37 as 00
  80.       else {printf("Winning number: %d\n", winningnum);}
  81.  
  82.    while(i < 4){
  83.    /*Converting strings to intergers*/
  84.    strcpy(str1, "00");
  85.    ret[i] = strcmp(board[i], str1); //compares input string to "00"
  86.      
  87.       if(ret[i] == 0){bet[i] = 37;}
  88.          else{bet[i] = atoi(board[i]);} //converts the string argument str to an integer
  89.      
  90.      {if(money[i] < 1){fprintf(stderr,"ERROR: Invalid input,amount:%d\n", i+1);}
  91.       if(bet[i] > 37||bet[i] == NULL||bet[i] < 0){fprintf(stderr,"ERROR: Invalid input,bet:%d\n", i+1);}
  92.        else{
  93.          if (bet[i] == winningnum) // if the bet matches the board no...
  94.             {printf(" No.%d, YOU WIN!\n  Payout: %.2f\n", bet[i],(money[i]*35)); //...print winning message
  95.              winnings[i] = money[i]*35; losses[i] = 0;}
  96.          else
  97.             {printf(" No.%d, you lose\n  Payout: 0\n", bet[i]); //...print losing message
  98.            winnings[i] = 0; losses[i] = money[i];} }
  99.                
  100.    i++;}} //increase i value by 1
  101.  
  102.  Twin = (winnings[0] + winnings[1] + winnings[2] + winnings[3]); //total winnings
  103.  Tloss = (losses[0] + losses[1] + losses[2] + losses[3]); //total loss
  104.  printf("--------------------\n");
  105.  
  106.  
  107.    if ((Twin - Tloss) > 0)
  108.       {wallet = (money[0] + money[1] + money[2] + money[3]) - Tloss + Twin; //calculate wallet value
  109.        printf("Wallet: %.2f\n", wallet);
  110.        printf("Total profit: %.2f", Twin - Tloss);} //print total profit of all bets
  111.    else
  112.       {printf("Wallet: 0\n");
  113.        printf("Total loss: %.2f", (Twin - Tloss)*-1);} //print total loss of all bets
  114. }