assignment output issues (chessboard)

This is the assignment http://venus.cs.qc.edu/~waxman/211/fancy%20print%20chessboard%20assignment%20how%20to.pdf

I'm having issues with the print: it is printing the board multiple times instead of once, and i am having issues with the queen printing on the boxes of the board.

**I TRIED USING THE CODE OPTION FOR THE CODE BUT IT ISN'T WORKING?**

//Thomas Arbelaez hw 8 - 8queens 1D using fancy print

#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;

bool isok(int b[], int c); //row and diagnal testing
void print(int b[]); //print function

int main()
{
int b[8], c = 0, count = -1;
b[0] = 0;

while (true)
{
c++;
if (c == 8)
{
count ++;
print(b);
c--;
}
else b[c] = -1;
for ( ; ; )
{
b[c]++;
if (b[c] == 8)
{
c--;
if (c == -1) exit(1);
else continue;
}
if ((isok(b, c)) == false) continue;
break;
} //end of infinite for loop

} //end of while loop

return 0;
}

bool isok(int b[], int c)
{
for (int i = 0; i < c; i++)
if (b[c] == b[i] || c - i == abs(b[c] - b[i])) return false;

return true;
}

void print(int b[])
{
int i,j,k,l;
typedef char box[5][7];
box bb,wb,wq,bq,*board[8][8];

//fill in bb=black box and wb=whitebox
for(i=0;i<5;i++)
for( j=0;j<7;j++)
{wb[i][j]=' ';
bb[i][j]=char(219);
wq[i][j] = ' '; //fill in queens in boxes
bq[i][j] = char(219);
wq[1][1] = wq[1][3] = wq[1][5] = char(219);
}

//fill board with pointers to bb and wb in alternate positions
for(i=0;i<8;i++)
for(j=0;j<8;j++)
if((i+j)%2==0)
board[i][j]=&wb;
else
board[i][j]=&bb;

// print the board via the pointers in array board
// first print upper border
cout<<" ";
for(i=0;i<7*8;i++)
cout<<'_';
cout<<endl;

// now print the board
for(i=0;i<8;i++)
for(k=0;k<5;k++)
{cout<<" "<<char(179); //print left border
for(j=0;j<8;j++)
for(l=0;l<7;l++)
cout<<(*board[i][j])[k][l];
cout<<char(179)<<endl; // at end of line print bar and then newline
}

//before exiting print lower border
cout<<" ";
for(i=0;i<7*8;i++)
cout<<char(196);
cout<<endl;
}
Last edited on
Topic archived. No new replies allowed.