求救!C语言纠错!跪求高手啊。。。写了一个程序,VC编译没问题,但是。。。运行就是个黑窗口啥也不出- =

两个子函数没啥问题。。。但是发不开了
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
int poker(int);
int code(int);
void main()
{
srand(time(NULL));
k:int shuffled_card[52],x=0,temp,i,k,A=0,B=0;
char j;
while(x<=52)
{
k=0;
temp=rand()%52;
for(i=0;i<x;i++)
if(temp==shuffled_card[i])k=1;
if(k==1)continue;
else {shuffled_card[x]=temp;x++;}

}
x=1;
A=poker(shuffled_card[0]);
printf("User get %c\n",code(shuffled_card[0]));
while(A<21||B<17)
{
printf("\nDo you want another card?<y/n>\n");
j=getchar();
if(j=='y')
{ if(poker(shuffled_card[x])==11||poker(shuffled_card[x])==12||poker(shuffled_card[x])==13)
A=A+10;
A=A+poker(shuffled_card[x]);
x++;
printf("User get %c\n",code(shuffled_card[x]));
}
else
{
printf("Now, it is my turn!\n");
if(poker(shuffled_card[x])==11||poker(shuffled_card[x])==12||poker(shuffled_card[x])==13)
B=B+10;
B=B+poker(shuffled_card[x]);
x++;
printf("Computer get %c\n",code(shuffled_card[x]));

}
}
if(A==21)
printf("\nYou Win!\n");
if(B==21)
printf("\nYou Lose!\n");
if(A!=21&&B!=21)
{
if(21-A<21-B)
printf("\nYou Win!\n");
else printf("\nYou Lose!\n");
}
printf("\nDo you want to play again?<y/n>\n");
j=getchar();
if(j=='y')goto k;
}
求教为毛。。。不运行啊
子函数。。。
int code(int a)
{
char n;
switch(a%13)
{
case 0:n='1';break;
case 1:n='2';break;
case 2:n='3';break;
case 3:n='4';break;
case 4:n='5';break;
case 5:n='6';break;
case 6:n='7';break;
case 7:n='8';break;
case 8:n='9';break;
case 9:n='10';break;
case 10:n='J';break;
case 11:n='Q';break;
case 12:n='K';break;
}
return n;
}

int poker(int a)
{
int n;
switch(a%13)
{
case 0:n=1;break;
case 1:n=2;break;
case 2:n=3;break;
case 3:n=4;break;
case 4:n=5;break;
case 5:n=6;break;
case 6:n=7;break;
case 7:n=8;break;
case 8:n=9;break;
case 9:n=10;break;
case 10:n=11;break;
case 11:n=12;break;
case 12:n=13;break;
}
return n;
}

while(x<=52)
{
k=0;
temp=rand()%52;
for(i=0;i<x;i++)
if(temp==shuffled_card[i])k=1;
if(k==1)continue;
else {shuffled_card[x]=temp;x++;}

}
会死循环啊,要改成x<52。不然当x=52的时候,for(i=0;i<x;i++)
if(temp==shuffled_card[i])k=1;这里已经存了0-51总过52张牌了,必然会重复的。所以一直会continue;死循环了。

还有的我看到像这里
if(poker(shuffled_card[x])==11||poker(shuffled_card[x])==12||poker(shuffled_card[x])==13)
A=A+10;
A=A+poker(shuffled_card[x]);
和这里
if(poker(shuffled_card[x])==11||poker(shuffled_card[x])==12||poker(shuffled_card[x])==13)
B=B+10;
B=B+poker(shuffled_card[x]);
应该都要加else把,不然就加两次了。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-05-07
或许你可以把这句while(x<=52)修改成while(x<52)

还有你的K:这句,重新换个名称吧,也换个位置,你这是c?你肯定是cpp文件,是默认用C++编译器的。
你变量定义应该是最开头,你看看你变量定义放哪里了,仔细思考下逻辑,主要是你那个K:该放哪里。
第2个回答  2013-05-07
char n;int code(int a)
你定义返回值是int,return n是char类型的
k:int shuffled_card[52],x=0,temp,i,k,A=0,B=0;
这句分开写
while(x<=52)
{
k=0;
temp=rand()%52;//随机值范围加大点吧
for(i=0;i<x;i++)
if(temp==shuffled_card[i])k=1; 、、//Z这句确定么,确定这不是个死循环么
if(k==1)continue;
else {shuffled_card[x]=temp;x++;}

}追问

k=1那个是用来判断产生的随机数是不是跟之前一样的,不会构成死循环吧。。。而且每次开始都会重置k=0啊。。

char n;int code(int a)
你定义返回值是int,return n是char类型的
改成 char code?

追答

可以,不过你这个程序干嘛用的。

追问

玩21点- -

追答

你这个是玩不了21点的

追问

那该。。。怎么改啊

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网