iso forbids comparison between pointer and integer

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>
using namespace 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





Last edited on
notice that x is a double dimensional array.
You do declare 'x' as 'int [][]', and 'c' as 'int'. 'x[i]' is not 'int'. You don't actually need/use two-dimensional array anywhere.

Your loops do range [0..8]. That is 9 values. Probably one more than what you intend.
yes am i not supposed to use nested for loop? and if not then how else would i do it with a 1d array?
Good point. You should have nested loop on output. Currently you don't have.

Better indentation of your code would make more obvious what you have.
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".
ok got it thanks for your help and youre right that is a silly input ill just make a if statement to reject answers bigger than 7
Topic archived. No new replies allowed.