Question: Codeblocks( C code) Explain the program to the user and ask if the user wants to play the game Card Count. Allow the user to
Codeblocks( C code)
Explain the program to the user and ask if the user wants to play the game Card Count. Allow the user to accept and play the game or exit.
Assuming the user wants to play, your program is to create a deck of 52 playing cards using one of the two schemes detailed above. The deck is to be shuffled randomly (see section below on generating random numbers), and then two hands of 5 cards are to be dealt to the two players (the user and the computer), alternating card dealing between the two. As each card is dealt, display each players updated hand. When complete, determine each players score by adding up the face values of the cards they are holding, and display these scores (Jack, Queen and King are 10 points, Ace is 11 points). The player with the highest score is to be declared the winner (allow ties). Determine if the player wants to play again; if not, exit. If so, recreate a new deck, shuffle it, and play again. Keep track of user wins, losses and ties (just for the current session of play). Your code should include appropriate pause points to allow the user to follow play. When the user choses to end the session of play, report the number of wins, losses, and ties to the screen.
In your program, you are to create and use the following functions:
void create_deck(int deck[]); This function accepts an array and writes to it to create a deck of 52 playing cards
void shuffle_deck(int size, int deck[]); This function accepts a deck of size cards (assume ) and randomly shuffles that deck by swapping two random cards in the deck
void display_card(int card); This function accepts an encoded number representing one of the 52 possible cards and displays the cards face and suite. Example display is below:
6 of Clubs
Ace of Diamonds
void display_hand(int size, int hand[]); This function calls display_card()size number of times to display a players hand.
int popCard(int *size, int deck[]); This function removes the top card from the deck and returns it to the calling function, while shifting the rest of the deck up one card. Note that the size of the deck must be decremented to reflect the loss of one card (This should be done using Call by Reference).
int findScore(int size, int hand[]); This function adds up the points of the face cards in a deck of size number of cards and returns that value.
To generate random numbers:
Include stdlib.h and time.h in your preprocessor directives
In the main body of the program, after all variables have been initialized use the srand() function to seed your random number generator rand() example: srand(time(NULL));
Random_Card_Index = rand() % 52; /* random number 0 to 51 */
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
