-
Notifications
You must be signed in to change notification settings - Fork 0
/
deal.c
34 lines (27 loc) · 861 Bytes
/
deal.c
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
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUM_SUITS 4
#define NUM_RANKS 13
int main(void){
bool in_hand[NUM_SUITS][NUM_RANKS] = {false};
int num_cards, rank, suit;
const char rank_code[] = {'2','3','4','5','6','7','8','9','t','j','q','k','a'};
const char suit_code[] = {'c', 'd', 'h', 's'};
srand((unsigned) time(NULL));
printf("Enter number of cards in hand: ");
scanf("%d", &num_cards);
printf("Your hand:");
while(num_cards > 0) {
suit = rand() % NUM_SUITS; /* Picks a random suit */
rank= rand() % NUM_RANKS; /* Picks a random rank */
if (!in_hand[suit][rank]) {
in_hand[suit][rank] = true;
num_cards--;
printf(" %c%c", rank_code[rank], suit_code[suit]);
}
}
printf("\n");
return 0;
}