This code prints coordinates for a square that another program uses. For space's sake I have cut out all the other program's code, but I believe it is a simple syntax mistake with my if() statements. I have followed the rules and looked just about everywhere and followed all of the C guidelines, but I keep getting 100 of the first coordinates followed by "no value". It seems that the program thinks ctr is not 0, where it is clearly defined.... Any reply would be appreciated.
int main()
{
int ctr;
int stopctr=0;
double xcoord[1];
double ycoord[1];
xcoord[0]=5;
ycoord[0]=-5;
ctr=0;
do{
if(ctr==1)
{
xcoord[0]=-5;
ycoord[0]=-5;
}
else if(ctr==2)
{
xcoord[0]=-5;
ycoord[0]=5;
}
else if(ctr==3)
{
xcoord[0]=5;
ycoord[0]=5;
}
else if(ctr=4)
{
xcoord[0]=5;
ycoord[0]=-5;
}
else{}
if((xcoord[0]==-4.9)&&(ycoord[0]==-5))
ctr=1;
else if((xcoord[0]==-5)&&(ycoord[0]==4.9))
ctr=2;
else if((xcoord[0]==4.9)&&(ycoord[0]==5))
ctr=3;
else if((xcoord[0]==5)&&(ycoord[0]==-4.9))
ctr=4;
else{}
printf("(%f,%f)\n",xcoord[0],ycoord[0]);
if(ctr==0)
{
xcoord[0]=xcoord[0]-0.1;
ycoord[0]=ycoord[0]+0;
}
else if(ctr==1)
{
xcoord[0]=xcoord[0]+0;
ycoord[0]=ycoord[0]+0.1;
}
else if(ctr==2)
{
xcoord[0]=xcoord[0]+0.1;
ycoord[0]=ycoord[0]+0;
}
else if(ctr==3)
{
xcoord[0]=xcoord[0]+0;
ycoord[0]=ycoord[0]-0.1;
}
else
{
printf("no value\n");
}
stopctr=stopctr+1;
}while(stopctr<100);
}