I am a C++ noob and I have just started learning it, and one of my assignments is to print a solution to the N-Queens problem, where the board would be N*N depending on user input. My IDE keeps showing me errors I don't understand in my code, even though to me it looks good and fine.
#include <iostream>
#include <array>
#include <stdexcept>
using namespace std;
int N;
bool safe(char board[N][N], int row, int col)
{
//checks if it's safe to place a queen
//doesn't give me any errors
}
bool placeQueen(char board[N][N], int col)
{
for (int i = 0; i < N; i++)
{
if ( safe(board, i, col) )
// says there is no matching function to call safe
{
board[i][col] = 1;
if ( placeQueen(board, col + 1) ){
//says cannot initialize parameter of type char(*)[*]
//with an Ivalue of type char(*)[N]
return true;
}
board[i][col] = 0;
}
}
return false;
}
void printAnswer(char board[N][N]){
//prints the final answer
}
int main()
{
int i, j;
try{
cout << "Enter the number of queens: ";
cin >> N;
char board[N][N];
for (int i = 0; i < N; i++){
for (int j = 0; i < N; i++){
board[i][j] = '.';
}
}
if ( placeQueen(board, 0) == false )
//no matching function to call placeQueen
{
throw runtime_error("Solution does not exist.");
return 0;
}
printAnswer(board);
//no matching function to call printAnswer
}
catch (runtime_error& excpt){
cout << excpt.what();
}
return 0;
}
It's probably me just being stupid but help would be appreciated, thanks!