Eight Queens, arrays

My program is supposed to make an array of 8 that symbolize for each column, the row that contains a queen, then prints the board. I just can't figure this one out...I thought I had it and then things went very wrong.

Suppose this was entered: 2 3 4 0 1 7 6 5
The output should look like this:
...Q....
....Q...
Q.......
.Q......
..Q.....
.......Q
......Q.
.....Q..


Here's my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;

int main()
{
  cout << "Enter the rows containing queens, in order by column: ";
//Collects the data for the array.
  int board[8];
  for(int i = 0; i < 8; i++)
    cin >> board[i];
//Prints the board.
  for(int t = 0; t < 8; t++)
  {
    int abc = 0;
    for(int a = 0; a != board[t]; a++)
    {
      cout << ".";
      abc = a;
    }
    cout << "Q";
    for(int f = 0; f < (6 - abc); f++)
    {
      cout << ".";
    }
    cout << endl;
  }

}


I just can't wrap my head around this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;

int main()
{
  cout << "Enter the rows containing queens, in order by column: ";
//Collects the data for the array.
  int board[8];
  for(int i = 0; i < 8; i++)
    cin >> board[i];
//Prints the board.
  for(int i = 0; i < 8; i++)
  {
    for(int j = 0; j < 8; ++j)
    {
        if(i == board[j])
            cout<<'Q';
        else
            cout<<'.';
    }
    cout<< endl;
  }
  return 0;

}


You seem to divide line into "pre-Q" and "post-Q" dots. I believe you don't need to do so.
I believe this code is simple and straightforward, but if you have questions, feel free to ask.

The code above worked for your test input.

Cheers!
Right, I was wondering why the dots were messed up. I traced the code over and over I just couldn't find it. Thanks for the help.
Topic archived. No new replies allowed.