<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2.  
  3. START
  4.  
  5. PSUEDO-CODE:
  6.     Run this four times:
  7.       do {
  8.       - input amount
  9.       - input bet number
  10.       }while(there is an error in the input)
  11.  
  12.     repeated four times (loop):
  13.       winNum = spinWheel()
  14.       if(bet == winNum):
  15.          show win
  16.          calculate profit
  17.          add to balance
  18.       else
  19.          show loss
  20.          calculate loss
  21.          subtract from balance
  22.  
  23.     show final balance and total profit/loss
  24.  
  25. */
  26.  
  27. #include<stdio.h>
  28. #include<time.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #define num 4   //numbers of input
  32.  
  33. struct rouletteNum { //roulette wheel values
  34.    char *val;
  35. }nums[38];
  36.  
  37. void initRouletteArray();
  38. int getTotalBalance(int, int[]);
  39. int getNewBalance(int, int);
  40. int spinWheel();
  41. int validateValue(int, char*);
  42.  
  43. int getTotalBalance(int balance, int amounts[]) {
  44.    int i;
  45.    for(i=0;i<num;i++) {
  46.       balance += amounts[i];
  47.    }
  48.    return balance;
  49. }
  50.  
  51. int spinWheel() {
  52.    return rand()%38;
  53. }
  54.  
  55. int validateValue(int amount, char* bet) {
  56.    int status = 0;
  57.    char temp[1] = " ";
  58.    //printf("betting value : %s\n", bet);
  59.    if(amount <= 0) {
  60.       printf("\n ERROR INVALID AMOUNT - AMOUNT CANNOT BE LESS THAN OR EQUAL TO ZERO - PLEASE RE-ENTER VALUES\n");
  61.       status = 1;
  62.    }
  63.    //if bet is null or incapable length
  64.    if(strlen(bet) == 0 || strlen(bet)>2) {
  65.       printf("\n ERROR INVALID BET - BET LENGHT CANNOT BE 0 OR GREATER THAN 2 - PLEASE RE-ENTER VALUES\n");
  66.       status = 1;
  67.    }
  68.    //if greater than 9
  69.    if(strlen(bet) == 2) {
  70.       //ascii value 0 and 3 repectively simply to check whether 10 tense is not 40s or above
  71.       if(bet[0]<48 || bet[0]> 51) {
  72.          status = 1;
  73.       }
  74.       //and unit tense is withing 0 - 9
  75.       if(bet[1]<48 && bet[1]>57) {
  76.          status = 1;
  77.       }
  78.       //if 10 unit tense is 3 and unit tense is under 6
  79.       if(bet[0] == 51 && (bet[1]<48 || bet[1] > 54)) {
  80.          status = 1;
  81.       }
  82.       //if there is a problem print the error
  83.       if(status) {
  84.          printf("\n ERROR INVALID BET - BET MUST BE A NUMERIC AND BETWEEN 0/00 - 36 - PLEASE RE-ENTER VALUES\n");
  85.       }
  86.    }
  87.    //else means the num is 0 - 9
  88.    else if(strlen(bet) == 1) {
  89.       if(bet[0]<48 && bet[0]>57) {
  90.          printf("\n ERROR INVALID BET - BET MUST BE A NUMERIC AND BETWEEN 0/00 - 36 - PLEASE RE-ENTER VALUES\n");
  91.          status = 1;
  92.       }
  93.    }
  94.    return status;
  95. }
  96.  
  97. int getNewBalance(int amount, int balance) { //hardcoded values of the spinning wheel
  98.    return balance + amount;
  99. }
  100.  
  101. void initRouletteArray() {
  102.    nums[0].val = "00";
  103.  
  104.    nums[1].val = "27";
  105.  
  106.    nums[2].val = "10";
  107.  
  108.    nums[3].val = "25";
  109.  
  110.    nums[4].val = "29";
  111.  
  112.    nums[5].val = "12";
  113.  
  114.    nums[6].val = "8";
  115.  
  116.    nums[7].val = "19";
  117.  
  118.    nums[8].val = "31";
  119.  
  120.    nums[9].val = "18";
  121.  
  122.    nums[10].val = "6";
  123.  
  124.    nums[11].val = "21";
  125.  
  126.    nums[12].val = "33";
  127.  
  128.    nums[13].val = "16";
  129.  
  130.    nums[14].val = "4";
  131.  
  132.    nums[15].val = "23";
  133.  
  134.    nums[16].val = "35";
  135.  
  136.    nums[17].val = "14";
  137.  
  138.    nums[18].val = "2";
  139.  
  140.    nums[19].val = "0";
  141.  
  142.    nums[20].val = "28";
  143.  
  144.    nums[21].val = "9";
  145.  
  146.    nums[22].val = "26";
  147.  
  148.    nums[23].val = "30";
  149.  
  150.    nums[24].val = "11";
  151.  
  152.    nums[25].val = "7";
  153.  
  154.    nums[26].val = "20";
  155.  
  156.    nums[27].val = "32";
  157.  
  158.    nums[28].val = "17";
  159.  
  160.    nums[29].val = "5";
  161.  
  162.    nums[30].val = "22";
  163.  
  164.    nums[31].val = "34";
  165.  
  166.    nums[32].val = "15";
  167.  
  168.    nums[33].val = "3";
  169.  
  170.    nums[34].val = "24";
  171.  
  172.    nums[35].val = "36";
  173.  
  174.    nums[36].val = "13";
  175.  
  176.    nums[37].val = "1";
  177. }
  178.  
  179. int main() {
  180.    char bets[num][3];
  181.    int amounts[num];
  182.    int winNumber[num];
  183.    int balance =0;
  184.    int i,j;
  185.    int profit = 0, loss = 0;
  186.    char choice;
  187.    char bet[2];
  188.  
  189.    srand(time(NULL));
  190.    initRouletteArray();
  191.    
  192.    do {
  193.    printf("\n");
  194.    //initialize values
  195.    profit = 0;
  196.    loss = 0;
  197.    balance = 0;
  198.    //----------------
  199.    printf("*** ROULETTE *** \n\n");
  200.    printf("ENTER AMOUNTS AND BETS: \n");
  201.    
  202.    for(i=0;i<num;i++) {
  203.       do{
  204.          printf("*** BET NUMBER: %d ***\n",i+1);
  205.          printf("AMOUNT TO BET: "); scanf("%d",&amounts[i]);
  206.          printf("STRAIGHT BETTING NUMBER: "); scanf("%s", bet); //scanf("%d",&bets[i]);
  207.       }while(validateValue(amounts[i], bet));
  208.       strcpy(bets[i],bet);
  209.    }
  210.    
  211.    balance = getTotalBalance(balance, amounts);
  212.  
  213.    for(i=0;i<num;i++) {
  214.       printf("\n");
  215.       winNumber[i] = spinWheel();
  216.       fflush(stdout); // for some reason it wasnt printing new line
  217.       printf("BALANCE: %d\n", balance);
  218.       printf("BET NUMBER: %d\n", i+1);
  219.       printf("BETTING AMOUNT: %d\n", amounts[i]);
  220.       printf("BETTING STRAIGHT NUMBER: %s\n", bets[i]);
  221.       printf("WINNING NUMBER: %s\n", nums[winNumber[i]].val);
  222.       if(strcmp(bets[i], nums[winNumber[i]].val) == 0) {//if won
  223.          printf("STATUS: WON\n");
  224.          printf("PROFIT: +%d\n", amounts[i]);
  225.          profit += amounts[i];
  226.          balance = getNewBalance(amounts[i], balance);
  227.       }
  228.       else { //if lost
  229.          printf("STATUS: LOST\n");
  230.          printf("PROFIT: -%d\n", amounts[i]);
  231.          loss += amounts[i];
  232.          balance = getNewBalance(-1 * amounts[i], balance);
  233.       }
  234.  
  235.       printf("\n NEW BALANCE: %d \n", balance);
  236.       printf("\n");
  237.       printf("\n");
  238.    }
  239.    
  240.    printf("\n");
  241.    printf("TOTAL PROFIT: %d\n", profit);
  242.    printf("TOTAL LOSS: %d\n", loss);
  243.    printf("YOUR FINAL BALANCE: %d\n", balance);
  244.    
  245.    }while(choice == 'y' || choice == 'Y');
  246.  
  247.    return 0; //exit state 
  248. }