Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkers 2

Status
Not open for further replies.

XoFF

Programmer
Jun 22, 2003
23
GB
i want to build a user defined checkers board but when i execute program,he's stuck in a endless loop... he's continously printing @'s

here is code:

#include <stdio.h>

#define WHITE &quot; &quot;
#define BLACK &quot;@&quot;

main()
{
int ZoneX,ZoneY,n,k,i,j;

printf(&quot;Give number of fields(n): &quot;);
scanf(&quot;%d&quot;,&n);

do{
printf(&quot;how large(k) are fields? (n*k<40): &quot;);
scanf(&quot;%d&quot;,&k);
}while(n*k>41);

for(ZoneY=0;ZoneY<n;ZoneY++){
for(i=0;i<k;i++){
for(ZoneX=0;ZoneX<n;ZoneX++){
for(j=0;j<k;i++){
if(ZoneX%2==0&&ZoneY%2==0)
printf(&quot;%s&quot;,BLACK);
else{
if((ZoneX+ZoneY)%2==0)
printf(&quot;%s&quot;,BLACK);
else
printf(&quot;%s&quot;,WHITE);
}
}
}
printf(&quot;\n&quot;);
}
}
}
 
> for(j=0;j<k;j++){ // inc wrong variable
You were incrementing i, not j
 
In the inner loop, if ZoneX%2==ZoneY%2 print black else print white
(you don't need 2 ifs)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top