-
Notifications
You must be signed in to change notification settings - Fork 0
/
cards.c
55 lines (46 loc) · 821 Bytes
/
cards.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
int main()
{
char card_name[3];
int count = 0;
do
{
puts("Enter the card_name: ");
scanf("%2s", card_name);
int val = 0;
switch (card_name[0])
{
case 'K':
case 'Q':
case 'J':
val = 10;
break;
case 'A':
val = 11;
break;
case 'X':
continue;
default:
val = atoi(card_name);
if ((val < 1 || val > 10))
{
puts("Value out of range!");
continue;
}
break;
}
/* Check if the value is 3 to 6 */
if (val > 2 && val < 7)
{
count++;
}
/* Otherwise check if the card was 10, J, Q, or K */
else if (val == 10)
{
count--;
}
printf("Current count: %i\n", count);
} while (card_name[0] != 'X');
return 0;
}