Question
Blackjack Program This project will simulate a blackjack program. It will put one player against the computer. The player will be able to wage money
Blackjack Program
This project will simulate a blackjack program. It will put one player against the computer. The player will be able to wage money on the game. The game will continue until the player does not want to play anymore or he/she runs out of money.
This program will start with a screen that says Welcome to CIS 126 Blackjack. Show this message for three seconds, clear the screen, and then go to the following prompt:
How much are you money are you playing with today? 1000
The user will then enter how much money they are playing with.
A sample execution of the program is as follows:
What is your wager? 10001
Sorry, you cant wager 10001, you only have 1000 left
What is your wager? 2
Sorry, the minimum bet for this table is 10
What is your wager? 50
Your cards are 5,10
Your sum is 15. Would you like to hit(H) or stay(S)? H
You got a J.
Your sum is 25. You lose this game. You have $950 left.
Score: Computer =1, Player 0
Would you like to play again? (Y/N?): Y
What is your wager? 950
Your cards are J,Q
Your sum is 20. Would you like to hit(H) or stay(S)? S
Computers cards: 6, 7, 5, 3
Computer got: 21
You lose this game. You have $0 left.
Score: Computer =2, Player 0
You do not have anymore money to play. Thank you for playing. Good bye.
Rules
The computer's cards should have a sleep of one second between each card to give it some suspense.
If the dealers sum is less than 17, the dealer must take another card.
If the dealers sum is 17 or above, the dealer must stand
The deck is has 52 cards in it. Cards cannot be reused. Cards must be generated
using some random number. You will need to keep track of the number and type of cards played. If all 52 cards are played, then you will need to reshuffle the deck.
Assume Ace is always 11, unless you are over, then assume it is 1.
The program will always ask the user to play again, unless the user has no more money to play.
Blackjack, a total of 21 on your first two cards, pays 3:2
Advanced playing (such as doubling down, splitting pairs) IS NOT required.
Hints:
You will need to use an array to hold the deck. An array of 52 will work fine.
Since we are using characters, we will need to use a getchar() after each scanf to get rid of the newline.
To simulate sleeping for 3 seconds heres the code.
int icrurrentime = 0;
int iendtime = 0;
icurrenttime = time( NULL ); //Get the current time
while( ( iendtime - icurrenttime ) < 3 ){ //Did the loop go for three seconds
iendtime = time( NULL );
}
Create the array like this:
int cards[52] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, //Array to initialize
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, //52 card
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,};//deck with 4 cards for each suit
In this deck, 11 is a J,12 is a Q, 13 is a K, and 14 is an Ace.
In order to deal a card
generate a random number between 0 and 51.
random = rand() ..;
See if the value of that array index is 0.
Does cards[random] == 0?
If it is, generate another random number until
cards[random] doesnt equal zero
Show the card, and then set
cards[random] == 0
Once all the cards have been dealt, then reset the array
to the original state.
BONUS (10 pts):
Allow user to double down and split pairs.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started