Code:

#include "stdafx.h"
#include <iostream>
using namespace std;
int queen[8][8];
bool addQueen(int x, int y)
{
int j;
if(queen[x][y] != 0)
{
return false; // Field is threatened or already taken or was already taken once.
}
for(int i = 0; i < 8; ++i)
{
if(queen[i][y] == -1)
{
return false; // Would threaten on row.
}
if(queen[x][i] == -1)
{
return false; // Would threaten on column.
}
}
// OK, we know we can place the queen.
queen[x][y] = -1;
for(int i = 0; i < 8; ++i)
{
if(queen[i][y] >= 0)
{
++queen[i][y]; // One more piece is threatening this field.
}
if(queen[x][i] >= 0)
{
++queen[x][i]; // One more piece is threatening this field.
}
}
for (int i=x-1,j=y+1;i>=0,j<=7;i--,j++)
{
if (queen[i][j]>=0)
++queen[i][j];
}
for (int i=x-1,j=y-1;i>=0,j>=0;i--,j--)
{
if (queen[i][j]>=0)
++queen[i][j];
}
for (int i=x+1,j=y+1;i<=7,j<=7;i++,j++)
{
if (queen[i][j]>=0)
++queen[i][j];
}
for (int i=x+1,j=y-1;i<=7,j>=0;i++,j--)
{
if (queen[i][j]>=0)
++queen[i][j];
}
return true;
}
bool removeQueen(int x, int y)
{
int j;
if(queen[x][y] != -1)
{
// There's no queen here.
return false;
}
queen[x][y] = -2; // There has been a queen here, so don't try placing one again.
for(int i = 0; i < 8; ++i)
{
if(queen[i][y] > 0)
{
--queen[i][y]; // One less piece is threatening this field.
}
if(queen[x][i] > 0)
{
--queen[x][i]; // One less piece is threatening this field.
}
}
for (int i=x-1,j=y+1;i>=0,j<=7;i--,j++)
{
if (queen[i][j]>0)
--queen[i][j];
}
for (int i=x-1,j=y-1;i>=0,j>=0;i--,j--)
{
if (queen[i][j]>0)
--queen[i][j];
}
for (int i=x+1,j=y+1;i<=7,j<=7;i++,j++)
{
if (queen[i][j]>0)
--queen[i][j];
}
for (int i=x+1,j=y-1;i<=7,j>=0;i++,j--)
{
if (queen[i][j]>0)
--queen[i][j];
}
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
int a, b, i, j; // ab to store the user co-ordinates ans i,j as counters
bool ans;
//int queen[8][8];
for (i = 0; i <= 7; i++) // Loop that runs while a = {0, 1, 2, ..., 7}
{
for (j = 0; j <= 7; j++) // Loop that runs while b = {0, 1, 2, ..., 7}
{
queen[i][j] = 0; // Initializing the "chest board" array
}
}
cout<<"Enter Row: ";
cin>>a;
cout<<"Enter Column: ";
cin>>b;
queen[a][b] = -1;
for(i = 0; i < 8; ++i)
{
++queen[i][b]; // One more piece is threatening this field.
++queen[a][i]; // One more piece is threatening this field.
}
for (i=a-1,j=b+1;i>=0,j<=7;i--,j++) //to lock the corresponding upper right diagonal
++queen[i][j];
for (i=a-1,j=b-1;i>=0,j>=0;i--,j--) //to lock the corresponding upper left diagonal
++queen[i][j];
for (i=a+1,j=b+1;i<=7,j<=7;i++,j++) //to lock the corresponding lower right diagonal
++queen[i][j];
for (i=a+1,j=b-1;i<=7,j>=0;i++,j--) //to lock the corresponding lower left diagonal
++queen[i][j];
for (i=0;i<8;++i)
{
for (j=0;j<8;++j)
{
if (i==a)
++i;
ans = addQueen(i,j);
if (!ans)
removeQueen(i,j);
}
}
for (i=0;i<8;i++)
{
for (j=0;j<8;j++)
{
cout<<"\t"<<queen[i][j];
}
cout<<"\n";
}
return 0;
}

And the output I got is: