为什么运行check函数的时候i,j的值恒为0?
#include <iostream.h>int n[5][5],r[5][5],y=1,i,j,xx,yy,k;
fg(int,int);
print(void);
check();
main()
{
for(i=0;i<=4;i++)
for(j=0;j<=4;j++)
{n[i][j]=0;
r[i][j]=0;}
cout<<"请输入起始行:";
cin>>i;
while(i<0||i>4)
{
cout<<"超范围了,请重新输入:";
cin>>i;
}
cout<<"请输入起始列:";
cin>>j;
while(j<0||j>4)
{
cout<<"超范围了,请重新输入:";
cin>>j;
}
n[i][j]=1;
r[i][j]=1;
y++;
print();
}
print(void)
{
cout<<endl;
int p,q;
for(p=0;p<=4;p++)
for(q=0;q<=4;q++)
{ cout<<n[p][q]<<"\t";
if(q==4)cout<<"\n";
}
cout<<endl;
if(y==25)cout<<"恭喜,恭喜!";
else fg(i,j);
}
fg(int i,int j)
{
xx=i;
yy=j;
cout<<"你现在将要放入数字"<<y<<"\n"<<"请输入下一行号:";
cin>>i;
cout<<i;
/* while(i<0||i>4)
{
cout<<"超范围了,请重新输入:";
cout<<"请输入下一行号:";
cin>>i;
}
cout<<"请输入下一列号:";
cin>>j;
while(i<0||i>4)
{
cout<<"超范围了,请重新输入:";
cout<<"请输入下一行号:";
cin>>i;
}
while(i==xx&&j==yy)
{
cout<<"笨蛋,你刚从那里来的啊"<<endl;
cout<<"你现在将要放入数字"<<y<<"\n"<<"请输入下一行号:";
cin>>i;
while(i<0||i>4)
{
cout<<"超范围了,请重新输入:";
cout<<"请输入下一行号:";
cin>>i;
}
cout<<"请输入下一列号:";
cin>>j;
while(i<0||i>4)
{
cout<<"超范围了,请重新输入:";
cout<<"请输入下一行号:";
cin>>i;
}
}*/
check();
n[i][j]=y;
r[i][j]=1;y++;
print();
}
check()
{
if(i==i1+1&&j==j1+2) k=1;
if(i==i1-2&&j==j1-1) k=1;
if(i==i1-2&&j==j1+1) k=1;
if(i==i1-1&&j==j1+2) k=1;
if(i==i1+1&&j==j1-2) k=1;
if(i==i1+2&&j==j1-1) k=1;
if(i==i1+2&&j==j1+1) k=1;
if(i==i1+1&&j==j1+2) k=1;
if(i==1&&j==1)k=1;
if(k==0)
{
cout<<i<<j<<k;
cout<<"你犯规了!";
i=xx;
j=yy;
fg(i,j);
}
}