In: Computer Science
How to do a blackjack game with the following rules and WITHOUT USING ARRAY
Part 1 – Displaying Cards
Write a function to display (print) a card.
sample program output
void displayCard(int card)
Prints the name of the card (ten of spades, queen of diamonds
etc.). The parameter should be a value between 1 and 13, from which
the type of card can be determined (1 = ace, 2 = two, …, 10, ==
ten, 11 = jack, 12 = queen, 13 = king).
The card suit (clubs, diamonds, hearts or spades) should be
determined randomly.
Part 2 – Generating Cards
Write a function to get a card.
int getCard()
Returns a random value between 1 and 13, representing a card (ace,
2, …, queen, king). You do not have to keep track of which cards
are dealt. So, if the game deals the queen of spades five times in
row that is perfectly acceptable.
Part 3 – Determining a Cards Score
Write a function to return a card's score.
int cardScore(int card)
Returns a value between 2 and 11 as described in the rules. Recall
that the score is the card's value except that aces are worth 11
and face cards are worth 10. The card parameter represents the card
for which the score is to be determined.
Part 4 – Dealing Cards
Now that you've completed Parts 1 and 2 you can write a function
that handles dealing cards.
int deal(bool isPlayer, bool isShown)
This function is responsible for:
1. Generating the next card to be dealt (Part 1)
2. Printing out what card was dealt (Part 2) and to whom, if needed
(see below)
3. Returning the card's score (Part 3)
The two Boolean parameters are related to printing out the card.
The isPlayer parameter is used to determine whether the word PLAYER
or DEALER should be printed at the start of the output. The isShown
parameter is used to determine if the card should be printed –
recall that the second card dealt to the dealer is hidden.
Part 5 – Playing a Hand
Parts 1 to 4 should be enough to get you started, and the detailed
instructions end here. Your next function should be to play a hand
of Blackjack, following the rules described above.
int playhand()
Responsible for playing a hand of Blackjack. Returns 1 if the
player won, -1 if the player lost and 0 if the player drew (magic
number alert).
There is quite a lot that goes into this function, and it is the
heart of the assignment. I would strongly recommend breaking it
down into other functions that implement the various phases of a
hand of Blackjack.
Part 6 – Game Loop
In your main function (or in another function called by main) write
a loop to ask the user if they want to play Blackjack, as shown in
the sample program output. The user should continue to play hands
of Blackjack until they choose to quit (enter a character other
than 'y').
Your program should keep track of whether the user wins, loses or
draws a hand (see the return value of the hand function) and print
a summary of these results when they exit the program.
The random sequence for the game must not be the same each time it
is played.
User Input and Program Output
Assume that the user enters correct input (lowercase 'y' to play a
hand, and lowercase 'h' or 's' to hit or stand) – but see
Extras.
Your output, wording, spacing and so on may differ from the samples
shown above. To receive full marks, it must correctly describe the
game and must be at least as pretty as mine (not that mine is
particularly pretty).
Part 1 answer: Following are the snapshot of the above program in c language. In the above question language is not mentioned. To run the below program the user needs to write it on the c programing editor.
Output: The snaposhot of the output of the above program for the input value of 11 is :-