c语言编程猜数字游戏,请看有什么问题。
# include & ltstdio.h & gt
# include & ltstdlib.h & gt
# include & lttime.h & gt
void main()
{
int回答[4],guess=0,times=0,a,b,I,j;
char c = ' Y
srand(time(NULL));/*注意这里*/
循环:if(c=='Y ')
{
for(I = 0;我& lt=3;i++)
{
答案[I]= rand()% 10;
for(j = 0;j & lt我;j++)
{
while(答案[I]= =答案[j])
答案[I]= rand()% 10;
}
}
for(I = 0;我& lt4;i++)
{
printf("%d ",答案[I]);
}
printf(" \ n ");
printf("请猜:\ n ");
而(a!=4)
{
a = 0;
b = 0;
times++;
printf("%d guess:\n ",次);
scanf("%d ",& amp猜测);
如果(猜& gt999 & amp& amp猜测& lt10000)
{
for(I = 3;我& gt=0;我-)
{
for(j = 0;j & lt4;j++)
{
if((int)(guess/pow(10,I))= =答案[j])
{
如果(i+j==3)
a = a+1;
其他
b = b+ 1;
}
}
guess = guess-(int)(guess/pow(10,i))*pow(10,I);
}
Printf(" %d不在%d的正确位置\n ",a,b);
}
else if(猜& lt1000 | |猜猜& gt9999)
{ break}
}}
如果(a==4)
{
printf("恭喜!你真聪明\ n ");
printf("要继续吗(Y还是N)");
scanf("%c ",& ampc);/*注意这里*/
if(c=='Y ')
{goto循环;}
}
}