Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help on C programming assignment. Strictly need to follow the instructions. This assignment will focus on the use of functions and passing of parameters.

Need help on C programming assignment. Strictly need to follow the instructions.

This assignment will focus on the use of functions and 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 both the dealer and the player try to accumulate cards whose point value adds up as close to 21 as possible, but no 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). If her 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 the 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 count 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 ranOut 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, point.getCard () is used to get the next card from the input file and assign its value to points. It should read the next character (i.e., 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, getCard () 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 getCard () it must check to see if point 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 an 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.).

You should not be using any global variables in your program. A global variable is a variable declared outside of main (). Output from your program should be sent to the terminal window (your screen) as well as the requested csis.txt output file.

Below is the content from bets.txt:

80

20

50

30

30

70

60

20

50

40

60

90

Below is the content from cards.txt:

45Q364QK2J827J3A5498TTA5TKK7652J9TQQ32JA4K7679A68938

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago