Question: Play Cards Take the program written last weekend that creates a deck of cards, shuffles them, and then lists them out. Modify the program to

Play Cards Take the program written last weekend that creates a deck of cards, shuffles them, and then lists them out. Modify the program to 'deal' two hands of cards (two players). Each player will be dealt 5 cards. Deal one to the first player, then one to second player. Repeat until both players have 5 cards in their hand. Then compute the total points in each player's hand and determine the winner with the most points. If a player has an ace, then count that as 11 points. Print out the winning player total points and then his cards. Then print out the losing player total points and his cards. Turn in both your code and a copy of the screen output.

//This is last week program

#include

#include

#include

#define NCARDS 52 #define NPROPS 2 #define NSUITS 4 #define NFACES 13

// card text values using array of pointers to preinitialized constant text strings char* suit[NSUITS]={"hearts","spades","clubs","diamonds"};

char* face[NFACES]={"ace","two","three","four","five","six","seven","eight","nine", "ten","jack","queen","king"};

// function prototypes used for manipulating cards void PrintCard(int deck[NCARDS][NPROPS], int i); void InitDeck(int deck[NCARDS][NPROPS]); void SwapCards(int deck[NCARDS][NPROPS], int src, int dest); void ShuffleDeck(int deck[NCARDS][NPROPS]); int GetPlayValue(int deck[NCARDS][NPROPS], int i);

int main() { //deck of cards // face, suite, card value int deck[NCARDS][NPROPS]; time_t rawtime=time(NULL);

int i;

srand(time(NULL)); // init the deck // loop on the chards InitDeck(deck); ShuffleDeck(deck);

// print the deck puts("The shuffled deck is:"); for (i=0; i

printf("Printed on %s",ctime(&rawtime)); system("PAUSE");

return 0; }

void PrintCard(int deck[NCARDS][NPROPS], int i) { int t_suit; int t_face;

t_suit = deck[i][0]; t_face = deck[i][1];

printf(" Card %d = %s of %s - Value = %d ", i+1, face[t_face], suit[t_suit], GetPlayValue(deck,i)); }

void InitDeck(int deck[NCARDS][NPROPS]) { int suit; int face; int row = 0; for (suit=0; suit < 4; suit++) for (face=0; face < 13; face++) { deck[row][0]= suit; deck[row][1]= face; row++; } }

void SwapCards(int deck[NCARDS][NPROPS], int src, int dest) { int temp;

temp = deck[src][0]; deck[src][0] = deck[dest][0]; deck[dest][0] = temp;

temp = deck[src][1]; deck[src][1] = deck[dest][1]; deck[dest][1] = temp; }

void ShuffleDeck(int deck[NCARDS][NPROPS]) { int src, dest, i;

for (i=0; i

int GetPlayValue(int deck[NCARDS][NPROPS], int i) { int face = deck[i][1]; if(face == 0) return 1; else if( (face > 0) && (face < 10)) return face+1; else return 10; }

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 Databases Questions!