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
136 lines (108 loc) · 1.91 KB
/
cards.c
File metadata and controls
136 lines (108 loc) · 1.91 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* Drew French */
/* Draws a random card
* and prints the name
* and suit properly.
*/
/* Didn't remember to use
* structs & enums for this
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int s;
int drawCard();
void getSuit(int);
int main()
{
int i;
for(i = 0; i < 5; i++)
{
srand(time(NULL));
getSuit(drawCard());
int j; /* These loops are here as a delay so rand() doesn't output the same thing 5 times. */
int k;
for(j = 0; j < (10000 + 5000 * i + ((rand() % 10 + 1) * 1000)); j++)
for(k = 0; k < (10000 + 5000 * i + ((rand() % 10 + 1) * 1000)); k++)
{}
}
return 0;
}
int drawCard()
{
int card = rand() % 13 + 2;
s = rand() % 4 + 1;
return card;
}
void getSuit(card)
{
if(card <= 10)
{
switch(s)
{
case 1: printf("%d of hearts\n", card);
break;
case 2: printf("%d of diamonds\n", card);
break;
case 3: printf("%d of clubs\n", card);
break;
case 4: printf("%d of spades\n", card);
break;
}
}
if(card == 11)
{
switch(s)
{
case 1: printf("Jack of hearts\n");
break;
case 2: printf("Jack of diamonds\n");
break;
case 3: printf("Jack of clubs\n");
break;
case 4: printf("Jack of spades\n");
break;
}
}
if(card == 12)
{
switch(s)
{
case 1: printf("Queen of hearts\n");
break;
case 2: printf("Queen of diamonds\n");
break;
case 3: printf("Queen of clubs\n");
break;
case 4: printf("Queen of spades\n");
break;
}
}
if(card == 13)
{
switch(s)
{
case 1: printf("King of hearts\n");
break;
case 2: printf("King of diamonds\n");
break;
case 3: printf("King of clubs\n");
break;
case 4: printf("King of spades\n");
break;
}
}
if(card == 14)
{
switch(s)
{
case 1: printf("Ace of hearts\n");
break;
case 2: printf("Ace of diamonds\n");
break;
case 3: printf("Ace of clubs\n");
break;
case 4: printf("Ace of spades\n");
break;
}
}
}