<mosaic.cnfolio.com>
PROGRAM
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. //#include<conio.h>
  6.  
  7. //print block letters
  8. void print_title(void);
  9. //Spin roulette
  10. void spin_roulette(void); //function to generate randome numbers
  11. void data_input(void);    //player's data input function
  12. //variables
  13. int cash_bet[4];       //array to store 4 interger numbers as amount of each bet
  14. int rand_num;         
  15. int read_key;     
  16. int balance, int_input,profit=0,loss=0;
  17. char first_name[10],last_name[10],input[2],bet_number[4][3];
  18. // wheel style with double zero on board
  19. char *Wheel_Data[] = { "00","27","10","25","29","12","8","19","31","18","6","21","33","16","4","23","35","14","2",
  20.                          "0","28","9","26","30","11","7","20","32","17","5","22","34","15","3","24","36","13","1" };
  21.  
  22.  
  23. void main(void)
  24. {
  25.    //Welcome & Title
  26.    printf("******************************************************************\n");
  27.    printf("******************************************************************\n");
  28.    print_title();
  29.    printf("\n******************************************************************\n");
  30.    printf("******************************************************************\n");
  31.  
  32.  
  33.    //welcome message
  34.    printf("\n********************Welcome to the Royal casino*******************\n\n");
  35.  
  36.    printf("Please Enter your first name and press enter key: ");
  37.    scanf("%s", first_name);   //save the first name of player in an array
  38.  
  39.    printf("\nPlease Enter your last name and press enter key: ");
  40.    scanf("%s", last_name)//save the last name of player in an array
  41.  
  42.    printf("\nHello Mr.%s %s please enter amount you want to deposit in your accout: ",first_name,last_name);
  43.    scanf("%d", &balance); //save the balance amount
  44.  
  45.    printf("\nTanks for depoiting $%d in your account your balance is $%d ",balance,balance);
  46.    puts("\n\n*******Please make four bets at a time.*******");
  47.  
  48.  
  49.  
  50.    //Loop to keep game going as long as you have cash and as you long as you wish to play
  51.    while (balance>0)
  52.    {
  53.       data_input(); //collect the data about player and bets
  54.       getchar();   
  55.       for (int i = 0; i <= 3; i++)   // repeats for 4 times
  56.        {
  57.         printf("\nYou have bet $%d on the number %s", cash_bet[i], bet_number[i]);
  58.         printf("\nPress ENTER to spin the roulette.");
  59.         getchar()//holding the program until player press enter
  60.         spin_roulette(); //function call to generate random number
  61.         printf("\n\n*****The ball has landed on %s*****", Wheel_Data[rand_num]); // display the number on which ball is landed
  62.         if (strcmp(Wheel_Data[rand_num],bet_number[i])==0) //compare bet number and the number on which ball is landed. returns 0 if matches
  63.           {
  64.            balance += cash_bet[i]//add bet amount into previous balance
  65.            printf("\n***Winner*** ***Winner***! You now have $%d in your account", balance)//shows wining message
  66.            profit += cash_bet[i]; //net profit in all rounds of game play
  67.           }
  68.         else  //if numbers do not match (loss)
  69.           {
  70.            balance -= cash_bet[i]; //deduction of bet amount from previous balance
  71.            printf("\nSorry. You've lost $%d. Your new balance is $%d\n", cash_bet[i], balance);//shows message
  72.            loss += cash_bet[i]; //net loss in all rounds of game play
  73.           }
  74.  
  75.         }
  76.      //end of game message
  77.      printf("\n***************************************************");
  78.      printf("\n********************End of Game********************");
  79.      printf("\n***************************************************");
  80.      printf("\nDear %s %s your net profit/loss in this round is given below", first_name, last_name);
  81.      printf("\nNet Profit: $%d\nNet Loss: $%d\nAccount Balance: $%d",profit,loss,balance); //shows net loss/profit
  82.      printf("\n** Press ESC button to exit or Enter button for next bet."); //prompt player whether to continue or exit
  83.      read_key = _getch(); //gets number for keypressed
  84.       if (read_key == 27) //if esc key is pressed then true
  85.           break//exit from while loop
  86.     }
  87. if (read_key!=27) // if user exit the game then dont show this message
  88.    {
  89.       printf("\nSorry. you dont have enough balance to continue the game. press enter to exit..");
  90.       //getchar();
  91.    //}
  92. }
  93.  
  94.  
  95. void print_title(void)
  96. {
  97.    printf("       \n");
  98.    printf("*******  ******   *      *  *      ****** ******* *******  ******        \n");
  99.    printf("*     * *      *  *      *  *      *         *       *     *        \n");
  100.    printf("******* *      *  *      *  *      *         *       *     *        \n");
  101.    printf("*   *   *      *  *      *  *      ****      *       *     ****        \n");
  102.    printf("*    *  *      *  *      *  *      *         *       *     *        \n");
  103.    printf("*     *  ******    ******   ****** ******    *       *     ******        ");
  104.    printf("                           ");
  105. }
  106.  
  107. void data_input(void)
  108. {
  109.    int i;
  110.    for (i = 0; i <= 3; i++)
  111.    {
  112.       printf("\n\nEnter  number[%d] between 00-36 you'd like to bet on> ",i+1);
  113.       scanf("%s",&bet_number[i]);
  114.       int_input = atoi(bet_number[i]);
  115.       while (int_input < 0 || int_input > 36)
  116.       {
  117.          puts("\nyou just entered an incorrect number please choose number between 0 and 36: ");
  118.          scanf("%s", &bet_number[i]);
  119.          int_input = atoi(bet_number[i]);
  120.       }
  121.       //strcpy(bet_number[i], input);
  122.       printf("Now how much money are you willing to risk on bet number %s? :", bet_number[i]);
  123.       scanf("%d", &cash_bet[i]);
  124.       while (cash_bet[i] > balance)
  125.       {
  126.          printf("\nYou don't have enough balance in your account please enter between 1 and %d? :", balance);
  127.          printf("\nhow much money are you willing to risk on bet number %s? :", bet_number[i]);
  128.          scanf("%d", &cash_bet[i]);
  129.       }
  130.    }
  131. }
  132.  
  133. void spin_roulette(void)
  134. {
  135.    srand((unsigned)time(NULL));
  136.    rand_num = rand()%36;
  137. }