一个小程序,但错误很多,哪位高手可以帮我改下啊,谢了!
#include <stdio.h>#include <stdio.h>
#include <stdio.h>
#define maxtime 8
#define winer 1
#define loser 0
int main()
{
int aid[4],num[4],i,j,times,key,key2,A,B;
char ch;
time_t now;
Initialize:now=time(0);
srand(now);
aid[0]=(rand()+90)%10;
delay(20);
aid[1]=(rand()+90)%10;
delay(20);
aid[2]=(rand()+90)%10;
delay(20);
aid[3]=(rand()+90)%10;
for(i=0;i<4;i++)
{for(j=0;j<4;j++)
{if((i!=j)&&(aid[i]==aid[j]))
goto Initialize;
}
}
printf(nnn);
times=1;
while(times<=MAXTIMES)
{
key=0;
key2=0;
printf(NO.%d:ntPlease input 4 different int numbers to play!nt,times);
scanf(%d,%d,%d,%d,&num[0],&num[1],&num[2],&num[3]);
for(i=0;i<4;i++)
{
if(!((num[i]<=9)&&(num[i]>=0)))
{
printf(tError!The numbers you input must be int numbers which from 0 to 9n);
key=1;
break;
}
}
if(key==1)
continue;
for(i=0;i<4;i++)
{
for(j=i+1;j<4;j++)
{
if(num[i]==num[j])
{printf(tError!The numbers you input must be different!n);
key2=1;
}
break;
}
}
if(key2==1)
continue;
A=0;
B=0;
for(i=0;i<4;i++)
{
if(num[i]==aid[i])
A++;
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(num[i]==aid[j])
B++;
}
}
B=B-A;
printf(tA%dB%dn,A,B);
if(A==4)
{
printf(Congratulations!n);
printf(Press any key to exit.!na);
getch();
return(winer);
}
else
{
printf(Press ENTER to continue,or press A to see about answer and exit.n); /*选择是否放弃,看答案*/
ch=getch();
if(ch=='n')
{
continue;
}
if((ch=='a')||(ch=='A'))
{
printf(The four numbers:%d,%d,%d,%dn,aid[0],aid[1],aid[2],aid[3]);
getch();
return(loser);
}
}
times++;
}
printf(Sorry!You have lost all the chances!nPress any key to exit!n);
getch();
}