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

Code C: Code a simple blackjack-like game. In this game, the dealer (computer) d

ID: 3792024 • Letter: C

Question

Code C:

Code a simple blackjack-like game. In this game, the dealer (computer) deals cards to the player, but the dealer does not play its own hand. For simplicity, the computer does not need to be aware of suits or face cards. To "deal", the computer can simply pick a random number from 2 to 11. (If you want ACEs low, then pick numbers from 1 to 11). An example play might look like this:

Welcome to Blackjack!

The objective of this game is for the sum of the cards in your hand to be as close to 21 as possible without going over 21.

If your cards total exactly 21, you win the game.

Would you like to try? (Y/N) y

OK. I will deal your first card. Type 'H' (hit) if you want me to deal another card or 'S' to stand.

Your card is: 6

You have 6 total. H)it or S)tand? H

Your card is: 11

You have 17 total. H)it or S)tand? H

Your card is: 5

You have 22 total.

BUSTED! Better luck next time.

<end>

Explanation / Answer

#include <stdio.h>
#include <stdio.h>

int main()
{
int num=0;
int total=0;
char option,hs;
   srand(time(NULL));// setting time null
   // printing bannners
printf("Welcome to Blackjack! ");
printf("The objective of this game is for the sum of the cards in your hand to be as close to 21 as possible without going over 21. ");
printf("If your cards total exactly 21, you win the game. ");
printf("Would you like to try? (Y/N)");
scanf("%c",&option);// taking option
if(option!='y'||option!='Y'){// if option is Y or y
// user prompting
printf(" OK. I will deal your first card. Type 'H' (hit) if you want me to deal another card or 'S' to stand. ");
   num=rand()%11;// generating randome between 1 to 11
   printf(" your card is ",num);// printing random number i.e your card
   total=total+num;// adding total to your card number
   printf("You have %d total. H)it or S)tand?:");// taking optins as stand or hit
   scanf("%c",&hs);
   if(hs=='s'||hs=='S'){// if you stand follows here
printf("Your score is",total);
   }else if(hs=='H'||hs=='h'){// if you hit it generates another random number and
   total=total+rand()%11;
   if(total==21){
       printf("own the game");
   }else{
       printf("You have %d total",total);
       printf("BUSTED! Better luck next time.");


   }
   }
}


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