[英]C Programming integer
I need to make a blackjack program. 我需要制作一个二十一点程序。 The thing is, as you can see in the code, there's a loop for generating cards without repetition..
事实是,正如您在代码中所看到的,有一个循环来生成卡片而无需重复。
If I hit a key it'll print a line like: "5-diamond" then hit another key and for example it prints: "8-clover" 如果我按下一个键,它将打印一行:“ 5-diamond”,然后按下另一个键,例如,它打印:“ 8-clover”
So how do I add those two together without messing up with the code. 因此,如何在不弄乱代码的情况下将两者加在一起。 Since I want to check the value of the sum of those two.
由于我要检查这两个值之和。 What do I need to do?
我需要做什么?
int cards()
{
int card[51];
int used[51];
int x = 0;
int playerhand = 0;
int dealerhand = 0;
int sum = 0;
while(!kbhit())
x++;
srand(x % 100000);
for(int i = 0; i <= 51; i++)
used[i] = 0;
for(;;)
{
int w;
do
{
w = rand() % 52;
}
while(used[w] == 1);
used[w] = 1;
int value = w % 13 + 1;
if(value >= 2 && value <= 10)
printf("%d-", value);
else
{
if(value == 1)
printf("Ace ");
if(value == 11)
printf("Jack ");
if(value == 12)
printf("Queen ");
if(value == 13)
printf("King ");
}
int suit = (int)(w / 13);
if(suit == 0)
printf("Clover");
if(suit == 1)
printf("Spade");
if(suit == 2)
printf("Heart");
if(suit == 3)
printf("Diamond");
printf("\n");
getch();
}
}
You should compute the sum
of the values and the count of Aces. 您应该计算值的
sum
和Aces的计数。
If a card is an Ace, add 11
, if it is a King, Queen or Jack, add 10
, otherwise add value
. 如果一张牌是A,则加
11
,如果是国王,王后或杰克,则加10
,否则value
。
If the sum
is greater than 21
and you saw Aces, deduct 10
for each Ace until you fall back below 22
. 如果
sum
大于21
并且您看到了A,请为每个A减去10
,直到降至22
以下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.