hi im trying to make a program that prints out an 8 by 8 board with 1 queen on each row
For example, if the user enters:
0,3,4,0,0,7,6,7
the program should create following board and print:
Q.......
...Q....
....Q...
Q.......
Q.......
.......Q
......Q.
.......Q
i think im doing it right but im getting a couple of errors that i cant fix any help is appreciated thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
usingnamespace std;
int main(){
int x [8] [8], r, c;
for(c = 0; c <= 8; c++){
cout << " Enter a number from 1 to 7 " << endl;
cin >> x [c];
}
for(r = 0; r <= 8; r++){
if(c == x [r])
cout << " Q " ;
else cout << " . " ;
}
return 0;
}
these are the errors thanks again
assignment15_meem.cpp: In function âint main()â:
assignment15_meem.cpp:7: error: no match for âoperator>>â in âstd::cin >> x[c]â
assignment15_meem.cpp:10: error: ISO C++ forbids comparison between pointer and integer
so should i set up r and c as separate arrays instead of 2d and go from there because i thought the only way i could get the picture is to use 2d array?
You do need only one 1d array and that is for keeping the position of Q in each line.
You should check that the input is valid. Telling the user to give a number [1..7] (which is erroneous advice, btw) does not prevent the user from typing "42".