1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#define DECKSIZE 52
#define MAXPLAYERS 4
#define MAXCHAR 40
#define MAXGAME 10
// function prototype
int deal();
int main(void)
{
// declaration
char player[MAXPLAYERS][MAXCHAR];
int playerCard[MAXPLAYERS][DECKSIZE];
int roundWinner[MAXGAME];
// set seed for random number
// read player names
for (int iPlayer = 0; iPlayer < MAXPLAYERS; iPlayer++)
{
printf("Enter the players name: ");
gets_s(player[iPlayer]);
}
for (int iPlayer = 0; iPlayer < MAXPLAYERS; iPlayer++)
printf("players %d name %s\n", iPlayer, player[iPlayer]);
// loop over number of games
for (int i = 0; i < MAXGAME; i++)
{
printf("Round %d\n", i);
for (int iPlayer = 0; iPlayer < MAXPLAYERS; iPlayer++)
{
srand((unsigned)time(NULL));
printf("%s's Hand:", player[iPlayer]);
for (int iCard = 0; iCard < 5; iCard++)
{
playerCard[iPlayer][iCard] = deal();
printf("%d ", playerCard);
}
printf("\n");
}
} // end for loop
// determine winner of game
// print out game results
printf("\n\n");
return (0);
} // end main()
int deal(void)
{
// Declaration
int deck[DECKSIZE] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,};
int cardNum = 0;
int cardVal = 0;
cardNum = rand() % 52;
cardVal = deck[cardNum];
return cardVal;
}
|