This assignment will focus on the use of functions and the passing of parameters. You are to construct a C program that plays a simplified game of blackjack. The rules are as follows:

  • A game consists of several hands, played until the cards run out. In each hand the dealer and the player try to accumulate cards whose point value adds close to 21 as possible, but not more than 21.
  • First the player gets a card, then the dealer gets a card, then the player gets a second card and the dealer gets a second card.
  • The player then has the opportunity to call for more cards. Her strategy will be to refuse cards when she gets to 16 points or more (i.e., she "hits" 15 or under) their point value goes over 21, the hand is over and the dealer wins.
  • If the player's point value did not go over 21, the dealer calls for more cards. He must refuse cards when he gets to 17 or more (i.e., he "hits" 16 or under). If he goes over 21 the player wins the hand. Otherwise the hand with the point value closer to 21 wins the hand. In case of a tie, the dealer wins.
  • If the player is dealt 21 on the first two cards, she has blackjack and immediately wins the hand. If the dealer has 21 on the first two cards, the hand is over and the dealer wins.
  • Cards 2 through 10 count their face value; K, Q, J count 10 points; A counts 1 if the point value in the hand is greater than 10, otherwise A counts 11.
  • A sample deck of cards can be found in: cards.txt.

The blackjack program should be organized as follows:

The program should contain a function called playHand () which contains two parameters: dealerWin and ranout (both semi-boolean values). playHand () is to play a hand of blackjack and then set dealerwin to true (1) if the dealer wins and false (0) otherwise. The main () function should repeatedly call PlayHand() and keep track of the total number of wins in the game using two variables: dealerTotal and playerTotal. However, playHand() should set Fanout to true (1) if it ran out of cards. In this case the program should not count this hand, print the total number of wins for both the player and the dealer, and exit.

The program should also contain a function called getCard () which has one! Integer parameter, points.getCard() is used to get the next card from the input file and assign its value to points. It should read the next character (ie card) in the file and set points to the appropriate value from 1 to 11. Note that a 10 will be represented in the file as T).

Also note that before reading a card, get Card() should check whether EOF IS true, and if it is signal that there are no more cards in the file by assigning a value of zero to points. Each time playHand() calls get Card() it much check to see if points is 0, meaning the cards have run out.

You should also build a betting system into your program. Allow the player to make a bet at the start of each hand and print out the total wins and losses at the end of each hand. If the player has 21 on her first two cards, she has blackjack and wins double her bet.

All functions should output information explaining what is happening (e.g., getCard() should write out the card it reads and its score, playHand () should write out the running point values as each new card is obtained, etc.).

As usual, make sure the program is well structured and readable. Remember be careful thought put into its organization will pay off at debugging time.

Once again, you should not be using any global variables in your program. A global variable is a variable declared outside of main()

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.