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..
#include <iostream>
usingnamespace 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;
}
}
#include <iostream>
usingnamespace 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.