Question: create a function that will assess the value of any card from the deck. Use the Black Jack rules for the card values. Hint: Cards

create a function that will assess the value of any card from the deck.
Use the Black Jack rules for the card values.
Hint: Cards will have string names. You will convert those to specific values based on the rules of the game.
Make sure that you have a function that receives a card and then will return the value of that card.
#include
#include
#include
#define DECK_SIZE 52
const char *suits[]={"Hearts", "Diamonds", "Clubs", "Spades"};
const char *ranks[]={"2","3","4","5","6","7","8","9","10", "Jack", "Queen", "King", "Ace"};
typedef struct {
const char *rank;
const char *suit;
} Card;
void generateDeck(Card *deck){
int i, j, k =0;
for (i =0; i <4; i++){
for (j =0; j <13; j++){
deck[k].rank = ranks[j];
deck[k].suit = suits[i];
k++;
}
}
}
void shuffleDeck(Card *deck){
int i;
for (i =0; i < DECK_SIZE; i++){
int randomIndex = rand()% DECK_SIZE;
Card temp = deck[i];
deck[i]= deck[randomIndex];
deck[randomIndex]= temp;
}
}
void displayDeck(const Card *deck){
int i;
for (i =0; i < DECK_SIZE; i++){
printf("%s of %s
", deck[i].rank, deck[i].suit);
}
}
int main(){
Card deck[DECK_SIZE];
srand(time(0));
generateDeck(deck);
printf("Original Deck:
");
displayDeck(deck);
shuffleDeck(deck);
printf("
Shuffled Deck:
");
displayDeck(deck);
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!