Hi, I've posted m code below and cant get it to work because of fatal error c1004 unexpected end-of-file found.
Appreciate any help.
#include <iostream>
using namespace std;
/*
//what i addedint q[8][8];
void printSolution();//int q[]);
void hereQueen(int q[], int n1, int n2);
*/
class Queens
{
bool canGo;
int squares, norm;
int *locationRow;
bool *column;
bool *lDiag;
bool *rDiag;
public:
int Nqueens;
Queens(int n)
{
canGo = true;
squares=n;
norm=squares -1;
locationRow = new int[squares];
column = new bool[squares];
lDiag = new bool[squares*2 - 1];
rDiag = new bool[squares*2 -1];
Nqueens = 0;
for(int i = 0; i < squares; i++)
{
locationRow[i] = -1;
column[i] = canGo;
};
for(int i = 0; i < squares*2 -1; i++)
lDiag[i] = rDiag[i] = canGo;
};
void hereQueen(int row)
{
char respond;
for(int col = 0; col < squares; col++)
if(column[col] == canGo &&
lDiag[row+col] == canGo &&
rDiag[row-col+norm] == canGo)
{
locationRow[row] = col;
column[col] = !canGo;
lDiag[row+col] = !canGo;
rDiag[row-col+norm] = !canGo;
if(row < squares - 1)
hereQueen(row+1);
else
{printSolution(); };
column[col] = canGo;
lDiag[row+col] = canGo;
rDiag[row-col+norm] = canGo;
};
};
void main()
{
int boardSize;
cout << "Starting Queens Problem..." << endl;
cout << "Enter the board size (2-12) -->";
cin >> boardSize;
Queens queens(boardSize);
queens.hereQueen(0);
cout << "Number of solution is" << queens.Nqueens << endl;
}
void printSolution() //int q[])
{
Nqueens++;
cout << "Solution for the " << squares << " Queens problem" << endl;
for(int i = 0; i < squares; i++)
{
for(int j = 0; j < squares; j++)
if(locationRow[i] == j)
cout << "Q";
else
cout << "*";
cout << endl;
};
};
}