How To Write A Blackjack Program In C

Posted onby admin

Im tasked with developing a simple blackjack program for a class. The program I have currently compiles and runs but it isnt paying out properly. A blackjack (21) should pay out 1.5*the wager, but it is doing it more than it should. Here is the code I have.

How To Write A Blackjack Program In C Language

How to write a blackjack program in c++

Edward Oakley Thorp (born August 14, 1932) is an American mathematics professor, author, hedge fund manager, and blackjack researcher. He pioneered the modern applications of probability theory, including the harnessing of very small correlations for reliable financial gain. How to write a cover letter is the next question that almost always comes up during a job search, no matter how many cover letters you have written in the past. It seems that figuring out how to write a cover letter is a tough task—perhaps even more difficult than writing a resume for some people. If you are using a compiler other than Turbo C, you will have to remove all the 'delay;' functions, and the header file. The delay function can be used only in Turbo C. It is used to create a time delay in the out put of the program. To know more about the delay function, Click here.

I know the problem is in my if else statements im just not sure how to make it work. Thanks for the help.

  • 3 Contributors
  • forum3 Replies
  • 4,682 Views
  • 7 Hours Discussion Span
  • commentLatest PostLatest Postby spookyfish

Recommended Answers

Program

This may or may not be part of the problem, but it needs to be adressed:

I did the same thing when I was first learning boolean logic and performing tests, and it took me a long time to understand why things are the …

How To Write A Blackjack Program In Computer

Jump to Post

All 3 Replies

This may or may not be part of the problem, but it needs to be adressed:

I did the same thing when I was first learning boolean logic and performing tests, and it took me a long time to understand why things are the way they are, but for now just trust me.... you would think the above is correct, but there is a specific way that boolean tests are handled, either in a singular expression, or a stand-alone variable (which yeilds true or false, non-zero and zero respectively)

So, keep in mind, boolean logic is handled individually per expression, or as a stand alone TRUE/FALSE flag.

spookyfishcommented:Helped me solve my problem really quickly!+0

How To Write A Blackjack Program In C Programming

P: 8
I've found some programs of how to create a standard game of blackjack on C++. But how would you do it using structs? Here is my assignment:
Problem Statement: The purpose of this project is to create a game of Blackjack, which can be played by one player against the dealer (represented by the computer). The deck of cards is to be stored as an array of Card structures.
Blackjack is played with a deck of 52 cards, consisting of four suits (hearts, clubs, diamonds, spades), each with 13 face values (Ace, King, Queen, Jack, 10, 9, ... 2). King, Queen, Jack and 10 all have a point count of 10; the Ace may be counted as either 1 or 11 whichever gives the higher count without going over 21; the remaining cards have their face values as their point count. The objective of the game for the player is to hold a higher point count than the dealer without going over 21. Ties go to the dealer.
Playing the game proceeds as follows
1. Dealer shuffles the cards and lays them face down (that means neither the player nor the dealer can see them until cards are dealt). Cards are dealt off the top of this deck.
2. One card is dealt face down to the dealer and one to the player. The player is allowed to see the card dealt to him/her, but cannot see the card dealt to the dealer.
3. One card is dealt face up to the dealer and to the player. The player can see both these cards.
4. On each successive round, both the player and the dealer may request one more card face up. Once the player or dealer declines a card, that person cannot receive any more cards. When both the player and the dealer decide to stop, or one of them goes over 21, cards are turned up and the winner is determined as follows. The point count used for each is the highest possible without going over 21 – with an Ace counting 11 or with an Ace counting 1. In case the player goes over 21 the dealer wins. In case the dealer goes over 21 and the player does not, the player wins. If neither goes over 21, the winner is determined by the highest point count, with ties going to the dealer.
5. To keep it simple - here is how the dealer figures out when to stop asking for cards. The dealer must continue to request cards until his total is 17 or greater. An Ace in the dealer's hand is always counted as 11 if possible without the dealer going over 21
How to play the game with a computer
Design and implement a program to simulate the game of Blackjack as described above.
Make the human-computer interface as clear and user-friendly as possible.
Cards shown should be the ones the player can see. Show the cards in the form, for example, “Ace of Diamonds”, “Three of Hearts”, etc. The player (user of the program) inputs choices for the player. The dealer choices must be played your program.
Requirements:
Representing the card deck:
The deck of cards should be stored as an array of Card structures, where each struct has three members – one string giving the suit, one string giving the card name, one integer giving the face value.
So, for example, the three of Diamonds will be represented as
suit as string “Diamonds”
name as string “three”
value as int 3
And the Jack of Spades will be represented as
suit as string “Spades”
name as string “Jack”
value as int 11
Initialize the card deck array with the correct values. The first card should be an “Ace” of “Diamonds” with a value of 1, the second card should be a “Two” of “Diamonds” with a value of 2, etc.
Write at least 5 functions
Write a function to shuffle the cards. . Here’s how to shuffle the cards: Pick 2 random numbers between 0 and 51 and exchange these cards in the deck – do this at least 25 times to get the card deck well shuffled.
When the game starts, the dealer/computer shuffles the cards (by calling the shuffle function) and then deals two cards to the player and two to the computer/dealer. Use two more arrays of card structures to hold the player’s cards and the dealer’s cards.
Write a second function to get a total count of the cards in a hand,
Now the game continues until either the computer/dealer or the player decides to stop or either’s total point count goes over 21.
Write a third function to get input from you, the player. Remember to let the player see all of their own cards as well as the top card held by the dealer. The player can decide to ask for another card, or to stop asking for cards, or to stop the game.
Write a fourth function to act as the computer/dealer playing the game. A dealer can only see their own cards. When it is the dealer’s turn, they can get another card or stop asking for cards (see the strategy described in 5 above.)
When the game is over (either has a total of over 21 or the player has requested that the game stops), the winner must be determined. Write a fifth function to determine and announce the winner.
Organize the program so that the main program calls functions to do the work. Be sure to provide comments describing what each function does as well as describing what each segment of your program is doing. Your program should be organized using separate files:
1 The .h file
2 The .cpp file containing the main program
3 One or more .cpp file(s) containing the functions
Submission: Zip all files and upload the zipped file.