minor problem with array

Apr 22, 2013 at 11:44pm
im trying to get

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 am getting the right answer it just only lets me do it once at a time for example i enter 0 and it prints the first line right away and then tells me to enter the second number but i want to enter all 7 numbers at once then it should print out the chess board anyone know what i can do 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];
cout << " Enter only whole numbers between 1 and 7 " << endl;
for( int c = 0; c <= 7; c++){
cin >> x [c];
for( int r = 0; r <= 7; r++)
if( r == x[c]) cout << " Q " ;
else cout << " . " ;
cout << endl;
}
return 0;
}




Apr 23, 2013 at 12:09am
You've nested your loops. Try to remove your loop that prints from the loop that asks for input.
Apr 23, 2013 at 12:09am
In your example the simplest solution is to enter all the numbers on one line

0 3 4 0 0 7 6 7 <return>

... or ...

move the loop that displays board outside loop that accepts data.
Apr 23, 2013 at 12:15am
got it thanks
Topic archived. No new replies allowed.