Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will program a modified game of Blackjack, in which a single user can play a

ID: 3555077 • Letter: Y

Question

You will program a modified game of Blackjack, in which a single user can play against the dealer (the computer). Your program must make use of functions in addition to main. Your program should play the game in the following sequence: Shuffle: Fill an array of 52 elements with random integers ranging from 1 to 11. This array will serve as your deck of cards. Deal: Select one card for the dealer and two cards to the player from the array. Cards must be picked, in order, from the end of the array. Print out the value of all these cards to the screen. Ask the Player for Choices: The player can choose to hit or stand. Hit means that the player would like to receive another card. Stand means that the player would not like to receive any more cards. Execute the player's choices until the player chooses to stand or he/she busts. Execute the Dealer's Choices: if the player has busted, the dealer has won. Otherwise, upon completion of the player's turn, the dealer hits until it gets closer to 21 than the player, or there's a bust. Special Notes For the purposes of this project, you DO NOT need to ensure that there is one card of each suit. The random number generator may create none, one, or multiple cards with the same value (ranging from 1 to 11). For the purposes of this project, face cards can be referred to by their numerical value. You will only need to generate "cards" ranging from 1-11, no need for Ace, Jack, Queen, or King. For the purposes of this project, you do not need to have a betting structure, as in real Blackjack. There are no bet or payout calculations required. Extra Credit 1: Code a function that will "draw" out a card every time a value is printed to the screen, using ASCII characters. The print function should draw a rectangle that looks like a playing card, and place the value of the card inside the rectangle. Extra Credit 2: Modify the deck of cards so that 1 and 11 display on the screen as Aces. This requires the user to see multiple sums when they receive an Ace (a sum if Ace is considered 1, and a sum if Ace is considered 11). Tens should display on the screen as Jacks, Queens and Kings (it is up to you to decide when to display each). Extra Credit 3: Add a "split" feature that allows the user to split if he or she receives two equal cards the first time they are dealt. Extra Credit 4: Add a feature to your program that generates four cards of each value (one of each suit) so that the deck generated by your program is the same as a deck of real playing cards. Extra Credit 5: Add feedback to the player so that he or she knows when it is appropriate to stand or hit. There are many web sites on the Internet that provide strategy tables to help with this. Extra Credit 6: Develop and implement a betting structure for your game. Extra Credit 7: Modify your program so that multiple users can play against the dealer.

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int cards[52],dealer,player;
static int ptr = 51;

void shuffleCards(){
   srand(time(NULL));
   dealer = player = 0;
   int i;
   for(i=0;i<52;i++){
       cards[i] = 1 + rand()%11;
   }
}

void deal(){
   printf("Dealer got: %d ",cards[ptr]);
   dealer+=cards[ptr--];
   printf("Player got: %d and ",cards[ptr]);
   player+=cards[ptr--];
   printf("%d ", cards[ptr]);
   player+=cards[ptr--];
}

void askChoice(int *ch){
   printf("1. Hit 2. Stand Enter your choice: ");
   scanf("%d",ch);
   printf("%d ", *ch);
   if(*ch == 1 || *ch == 2){
       return;
   }else{
       printf(" Wrong choice. Enter again.. ");
       askChoice(ch);
   }
}

int main(int argc, char const *argv[])
{
   int ch;
   shuffleCards();
   deal();
   while(1){
       askChoice(&ch);
       if(ch==1){
           printf("Player got: %d ", cards[ptr]);
           player+=cards[ptr--];
           if(player>21 && dealer<=21){
               printf("Player busted!!! Dealer's total: %d ", dealer);
           }else if(player<21 && dealer>21){
               printf("Dealer busted!!! Player's total: %d ", player);
           }if(player<21 && dealer<21 && player>dealer){
               printf("Dealer busted!!! Player's total: %d ", player);
           }
       }else if(ch==2){
           printf("Dealer got: %d ", cards[ptr]);
           dealer+=cards[ptr--];
           if(dealer>21 && player<=21){
               printf("Dealer busted!!! Player's total: %d ", player);
           }else if(dealer<21 && player>21){
               printf("Player busted!!! Dealer's total: %d ", player);
           }else if(player<21 && dealer<21 && dealer>player){
               printf("Player busted!!! Dealer's total: %d ", player);
           }
       }
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote