Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* *******************************************************
- * ####### ####### ####### # ## # ####### *
- * # # # # # ### # # # *
- * # ####### ####### # # ## # # # *
- * # # # # # # ## # # # *
- * ####### # # ####### # # ### ####### *
- *******************************************************
- */
- #include <stdio.h> // Included for printf, scanf
- #include <stdlib.h> // Included for system, srand, rand
- #include <time.h> // Included for time
- #define SUCCESS 0 // Defined for return
- int main()
- {
- // Constants definition:
- const short SLOTS_CHOICE = 1;
- const short ROULLETE_CHOICE = 2;
- const short MINIMUM_BID = 20;
- const short MINUMUM_ROULLETE_NUM = 1;
- const short MAXIMUM_ROULLETE_NUM = 36;
- // Variables definition:
- short gameChoice;
- int balance = 100;
- int gambleValue;
- srand(time(NULL));
- printf("Welcome to THE CASINO!\n");
- printf("Your current balance is %d$.\n", balance); // Presents balance
- printf("Which game would you like to play this time? <Choose 1 for Slots or 2 for Roulette> ");
- scanf("%d", &gameChoice); // Receives game choice
- if(SLOTS_CHOICE != gameChoice && ROULLETE_CHOICE != gameChoice) // Checks if game choice is valid
- {
- printf("Your choice is invalid!\n");
- }
- else
- {
- printf("How much money would you like to gamble on? <The minimum is 20$, and your current balance is %d$> ", balance);
- scanf("%d", &gambleValue); // Receives gamble value
- if((gambleValue > balance) || (gambleValue < MINIMUM_BID)) // Checks if gamble value is valid
- {
- printf("Your gamble is invalid!\n");
- }
- else
- {
- if(SLOTS_CHOICE == gameChoice) // Enters Slots game
- {
- balance = balance - gambleValue; // Subtracts gamble value from current balance
- printf("Welcome to SLOTS!\n");
- int firstSign = (rand() % 3) + 35; // Random number between 35 and 37 (ASCII values of #, & and %)
- int secondSign = (rand() % 3) + 35; // Random number between 35 and 37 (ASCII values of #, & and %)
- int thirdSign = (rand() % 3) + 35; // Random number between 35 and 37 (ASCII values of #, & and %)
- printf("The machine has generated these symbols:\n");
- printf("%10c%10c%10c\n", firstSign, secondSign, thirdSign);
- if((firstSign == secondSign) && (secondSign == thirdSign)) // Checks if the player has won
- {
- printf("Congratulations! You have won!\n");
- balance = balance + (gambleValue * 8); // Adds the amount of money earned to the balance
- }
- else
- {
- printf("Sorry! You have lost!\n");
- }
- }
- else if(ROULLETE_CHOICE == gameChoice) // Enters Roulette game
- {
- printf("Welcome to ROULETTE!\n");
- int biddingNum;
- printf("Please enter your bidding number: ");
- scanf("%d", &biddingNum); // Receives bidding value
- if(MINUMUM_ROULLETE_NUM > biddingNum || MAXIMUM_ROULLETE_NUM < biddingNum) // Checks if the bidding number is valid
- {
- printf("The number you have chosen is invalid!\n");
- }
- else
- {
- balance = balance - gambleValue; // Subtracts gamble value from current balance
- int rouletteResult = (rand() % 36) + 1; // Random number between 1 and 36
- printf("The machine has chosen the number %d!\n", rouletteResult);
- if(rouletteResult == biddingNum) // Checks if the player has won
- {
- printf("Congratulations! You have won!\n");
- balance = balance + (gambleValue * 35); // Adds the amount of money earned to the balance
- }
- else
- {
- printf("Sorry! You have lost!\n");
- }
- }
- }
- }
- }
- if(balance) // Checks if the player has money after game play
- {
- printf("Your final balance is %d$. Hope to see you next time!\n", balance); // Presents balance after game play
- }
- else
- {
- printf("Your final balance is %d$ - You lost all your money! What a shame...\n", balance); // Presents 0 balance
- }
- system("PAUSE");
- return(SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement