forked from CPRF-Session2/Assignment6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcards.c
More file actions
77 lines (59 loc) · 1.31 KB
/
cards.c
File metadata and controls
77 lines (59 loc) · 1.31 KB
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
/* Jared Wasserman -- cards.c */
/*This program random chooses 5 cards and prints them out. It uses structs and enums.*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
struct card{
int card;
int suit;
};
enum suits {HEARTS,SPADES,CLUBS,DIAMONDS};
struct card drawCard(){
struct card drawnCard={(rand()%13+1),(rand()%4)};
return drawnCard;
}
void getSuit(struct card pickedcard){
if(pickedcard.suit==HEARTS){
printf("hearts\n");
}else if(pickedcard.suit==SPADES){
printf("spades\n");
}else if(pickedcard.suit==CLUBS){
printf("clubs\n");
}else if(pickedcard.suit==DIAMONDS){
printf("diamonds\n");
}
}
void printCard(struct card pickedcard){
int x = pickedcard.card;
switch(x){
case 1:
printf("\tAce of ");
break;
case 11:
printf("\tJack of ");
break;
case 12:
printf("\tQueen of ");
break;
case 13:
printf("\tKing of ");
break;
default:
printf("\t%d of ",x);
}
}
int main(){
srand(time(NULL));
printf("Drawn Cards:\n");
struct card c1=drawCard();
printCard(c1);getSuit(c1);
struct card c2=drawCard();
printCard(c2);getSuit(c2);
struct card c3=drawCard();
printCard(c3);getSuit(c3);
struct card c4=drawCard();
printCard(c4);getSuit(c4);
struct card c5=drawCard();
printCard(c5);getSuit(c5);
return 0;
}