editing function messed up this post. For more information, feel free to PM me. Sorry about that! --alc6379

Recommended Answers

All 4 Replies

it will require me some time to find the error in ur program, but in my case it reached the line:
printf("\n done?"); I put this in to see if it got to here. never got here yet.
u never got there bcoz u have not put braces after the following ststement:

if (column != j)


if (((ROW-i)/(COLUMN-j)) == 1)
board[j]=0;
if (((ROW-i)/(COLUMN-j)) == -1)
board[j]=0;


the braces need to put  after the if statement like this
if (column != j)
{
if (((ROW-i)/(COLUMN-j)) == 1)
board[j]=0;
if (((ROW-i)/(COLUMN-j)) == -1)
board[j]=0;
}

and one more syntax error is that in a if statemen u have to give two == while comparing
if(board[row][column]==1)
do keep this in mind bcoz the compiler does not identify it as an error but if only one = is given then it will assign the value to the variable.

the program requires a long time to run bcoz u have 8 consecutive for loops.

and the other error i got was :
function printboars should have a protoytype, but it was solved when i defined the function outside int main(). i don't know why this happened.

Thanks, its back to the program.....I'll update my progress later; have to play my dailey halo after class to prepare my mind for typing code stuff.

My brain is fried from gearing up for dead week and finals.

:cheesy:

I feel so close and yet so far away. Here is what I have done with your suggestions, but it is still not printing my data to file or screen, I have it currently set to print to file. After debug, I get no warnings or anything. I feel real close, it makes the fan go on, in my laptop, LOL--ok here is what I have now. Thanks for your constructive advice.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



# include <stdio.h>



int board[8][8],*ptr=&board[0][0],a,b,c,d,e,f,g,h,k,n,o;
void checkboard();
void printboard();
void zeros(int row, int column);
int main(void)
{
// declare varibles



// set all spaces to 1
for(k=0;k<=63;k++)
*(ptr+k)=1;
// place a queen in each column
for(a=0;a<=7;a++)
{


for(b=0;b<=7;b++)
{


for(c=0;c<=7;c++)
{


for(d=0;d<=7;d++)
{


for(e=0;e<=7;e++)
{


for(f=0;f<=7;f++)
{


for(g=0;g<=7;g++)
{


for(h=0;h<=7;h++)
{
// this places all of the zeros
zeros(0,a);
zeros(1,b);
zeros(2,c);
zeros(3,d);
zeros(4,e);
zeros(5,f);
zeros(6,g);
zeros(7,h);
// this checks if there are eight queens on the board
checkboard();
}
}
}
}
}
}
}
}


printf(" done?");



return ;



}


void zeros(int row, int column)
{
// make all spaces with hits 0's
int board[8][8],i=0,j=0;
double ROW,COLUMN;


ROW=row;
COLUMN=column;
if(board[row][column]==1)
{
board[row][column]=3;


for(i=0;i<=7;i++)
{
for(j=0;j<=7;j++)
{
// places the zeros in the rows and columns
if (i== row)
board[j]=0;
if (j== column)
board[j]=0;
// makes the diagonal zeros
if (column != j)
{
if (((ROW-i)/(COLUMN-j)) == 1)
board[j]=0;
if (((ROW-i)/(COLUMN-j)) == -1)
board[j]=0;
}
}
}
}
return ;
}


void checkboard() // this checks for eight queens
{
int board[8][8],l,m,threes=0;


for(l=0;l<=7;l++)
{
for(m=0;m<=7;m++)
{
if (board[l][m]==3)
threes++;


}
}
if (threes == 8)
printboard();


return  ;
}


void printboard() // this prints out the board to a data file
{
int board[8][8],n,o;
FILE *solutions;
solutions = fopen("solutions.dat","w");//I originally wanted to have it print to file but
//I couldn't see what it was doing--nothing I see,LOL


for(n=0;n<=7;n++)
{
for(o=0;o<=7;o++)
{
fprintf("solutions,%i %i ",board[n][o]);
}
printf("\n");
printf("\n I finally got here!");
}
fclose(solutions);
return ;
}

If you have time, I updated the code a bit--I still do not get any desired output, but the debugger liked it.

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.