Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm sorry for posting homework, but I can't figure out why this thing isn't running right. Could someone please take a look at this and see what I did wrong? THANKS!
#include
int row, col, count=0;
int CheckBoard(int row, int col);
int board[8][8]={0};
main()
{
int PlaceQueen=0;
do
{
col=0;//loop to check the board
do
{
printf("%d %d\n", row, col);
if(CheckBoard(row, col)==1)
board[row][col]=3;
else col++;//clears the column in column is over 8 and removes queen from counter
if(col>8){
row--;
for(col=0; col0);//checks diag #3 (--)
printf("diag3\n");}
if(x!=7){
r=row;
c=col;
do
{
if(board[r][c]!=3){
c--;
r--;}
else
x=7;
}while(x!=7&&c>0&&r>0);//checks diag #4 (-+)
printf("diag4\n");}
if(x!=7){
r=row;
c=col;
do
{
if(board[r][c]!=3){
c--;
r++;}
else
x=7;
}while(x!=7&&c>0&&r>0);}printf("%d %d\n", row, col);
//returns 1 if no queen attack, 0 if queen attack
if(x!=7)
return 1;
else
return 0;
}

I don't think that anyone has a problem with homework posting if you have attempted to write some code and are asking for help. It's the people that want it all done for them that get ignored/flamed.
I very recently heard about the "8 queens" problem, otherwise I wouldn't know what you are trying to do. A little description of what you want to do and what is happening would be helpful.

Good point.
The 8 queens problem is to take a regular 8x8 checker board and place 8 queens on it so that no queen can attack any other queen using standard chess moves.
You will notice alot of superfulous printf statements in this code, I put them in to tell me where the program made it to so that I could hopefully figure out where it went wrong. It didn't help.
I'm sure that its something little that I overlooked, but I've been staring at it for too long and can't see it. Thats why I'm hoping that you guys here will be able to help.
Thanks.

I have once again changed it and wanted to see if anyone was out there that could help me understand this thing. The assignment is already turned in, so I just want to see where my mistake was and have a working program for future reference. The include is . Thanks.
#include
int row, col, x=0;
int c, r, count;
int board[8][8]={0};
int PlaceQueen=0;
main()
{
do
{
c=0;
do
{
//checks horizontal (-)
printf("horizontal\n");
do
{
if(board[row][c]!=3)
c++;
else
x=7;
}while(c0);
printf("r=%d, c=%d, x=%d\n", r, c, x);//checks diag #3 (--)
printf("diag3\n");}
if(x!=7){
r=row;
c=col;
do
{
if(board[r][c]!=3){
c--;
r--;}
else
x=7;
}while(c>0&&r>0);
printf("r=%d, c=%d, x=%d\n", r, c, x);//checks diag #4 (-+)
printf("diag4\n");}
if(x!=7){
r=row;
c=col;
do
{
if(board[r][c]!=3){
c--;
r++;}
else
x=7;
}while(c>0&&r8){
row--;
for(col=0; col8;col++){
board[row][col]=0;}
col=0;
PlaceQueen--;
printf("place queen minus=%d\n",PlaceQueen);}}while(board[row][col]==0);
printf("Made it farther\n");
PlaceQueen++;
printf("place queen=%d\n",PlaceQueen);
row++;
printf("%d %d\n", row, col);
}while(PlaceQueen8);//prints out answer
count=1;
for(row=0; row8; row++){
for(col=0; col8; col++){
if(board[row][col]!=0){
printf("%d ",count);
count++;}
}
}
return 0;
}

![]() |
Highly anynomous proxies
|
help in movie booking sys...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |