Question: C++ Blackjack program Part I: Here is one way to draw a random card from a deck. Create a string called suit that contains the
C++ Blackjack program
Part I:
Here is one way to draw a random card from a deck.
Create a string called suit that contains the characters CDHS, which stand for Clubs, Diamonds, Hearts, and Spades.
Create another string called rank that contains numbers 2-9, T for ten, J for Jack, Q for Queen, K for King, and A for Ace.
Use the rand() function to select a random suit (out of 4) and a random rank (out of 13). Store these variables as strings.
Concatenate the strings together to make a new string called card.
Part II:
Here is another way to draw a random card from a deck.
First, we will create a stringstream called deck. As before, create strings suit and rank.
Next, use two for loops, one inside the other, to cycle through each rank and suit to create a string called cards as follows:
CA C2 C3 ST SJ SQ SK
Finally, use the rand() function to pick a random card (out of 52). Store the result in a substring called draw.
Hint: Your string should have 156 characters. Each card consists of 3 characters: a suit, a rank, and a space. Make your substring as follows:
draw = cards.substr(3*x, 3);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
