I have only started learning borland c++ programming a few months ago, I'm actually a math student, so my knowledge of c++ is pretty limited. I have an assignment where X represents an ant that moves around in a 7x7 grid box. It can move up, left, down or right by 1 step at a time. I have already written the code, but sometimes the 1st 7x7 grid displayed is sometimes distorted. It only displayed a 7x3 grid. Please let me know what is the mistake I made. I know my course is not so efficient, I just want to get it working first. Please help me! I'm dying! =(
#include
#include
#define size 20
void main()
{
srand(time(0));
int box[size][size];
int i,j,y=0, count, random, key;
for (i=0;i<7;i++)
for (j=0;j<7;j++){
box[i][j]=y+1;
y= box[i][j];
}
i=3;
j=3;
for (count=1;;count++)
{
random = rand()%4;
if (count==1)
key= box[3][3];
else if (random==0)
key= box[i][j=j+1];
else if (random==1)
key= box[i][j=j-1];
else if (random==2)
key= box[i=i-1][j];
else if (random==3)
key= box[i=i+1][j];
if (i<0||j<0)
goto out;
if (i>=7||j>=7)
goto out;
{
cout<<" ";
for(int line=0;line<7;line++)
cout<<"--- ";
}
cout<