### i suspect this is the most simple array problem here but

shurley this should ouput a table, i feel like maybe i have forgotton something
fundemental, instead i get flat lines no big beautiful table.

did you know victorians made skirts for tables because they thought the bare legs were immoral!

 ``12345678910111213141516171819202122232425`` ``````#include #include using namespace std; char z = '*'; char x = ' '; char brdray [8] [8]= { {z,z,z,z,z,z,z,z} ,{z,x,x,x,x,x,x,z} ,{z,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,z} ,{z,x,x,x,x,x,x,z} ,{z,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,z}, {z,z,z,z,z,z,z,z} }; void getboard(); int main () { getboard (); return 0; } void getboard() { for (int a = 0;a<7;a++) { for (int b =0;b<7;b++) cout << brdray [a][b]; } }``````
You need to to output a new line character when you want a new line.
`cout << '\n';`
carriage return (\n)
 ``123456789101112131415`` ``````void getboard() { for (int a = 0;a<7;a++) { for (int b =0;b<7;b++) cout << brdray [a][b]; cout<<"\n"; /*newline character is needed, you can also use a Line feed operator cout<
Last edited on
You have 8 items in the array, so the limit in for loops should be 8 as well.

Your initialisation of the array doesn't have to be on 1 line.

 ``12345678`` ``````char brdray [8] [8]= { {z,z,z,z,z,z,z,z} , {z,x,x,x,x,x,x,z} , {z,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,z} , {z,x,x,x,x,x,x,z} , {z,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,z}, {z,z,z,z,z,z,z,z} }``````

There is a bit of an unwritten rule that code shouldn't be longer than 80 chars per line. This saves having to scroll sideways all the time, and is easier in case some one wants to print it.

Edit: You need single quotes around each char 'z' and 'x'

HTH
Last edited on
is okay z and x are char names not the values...just with endline, i get iether lon ****** ** etc or lots of lines eg
*
*
*
*
*
*
*

like that, i also get amazing grids of * that repeats, as cool as it is its not what im after
Ok, I missed the variables x & z.

Can you post your new code again, I don't see why it shouldn't work given the suggestions already.

 ``1234567891011121314151617181920212223242526272829303132333435`` ``````#include #include using namespace std; char you = '^'; char z = '*'; char x = ' '; char brdray [8] [8]= { {z,z,z,z,z,z,z,z} ,{z,x,x,x,x,x,x,z} ,{z,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,z} ,{z,x,x,x,x,x,x,z} ,{z,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,z}, {z,z,z,z,z,z,z,z} }; void getboard(); int main () { getboard (); return 0; } void getboard() { for (int a = 0;a<8;a++) { for (int b =0;b<8;b++) cout << brdray [a][b]<
Last edited on
been trying to create a class that has the functions in it to get a chars position and then initialise it to a new one... think i need to keep practicing before i move to allegro
 ``123456789`` ``````void getboard() { for (int a = 0;a<8;a++) { for (int b =0;b<8;b++) cout << brdray [a][b]<

The Line feed operator is not to be appended after the cout<<brdray[a][b];

cout<<endl; must be placed after the inner for loop, ie

 ``12345678910111213`` ``````void getboard() { for (int a = 0;a<8;a++) { for (int b =0;b<8;b++) { cout << brdray [a][b]; //the braces r not necessary since its a single stat } cout<

So you can also write

 ``123456789101112`` ``````void getboard() { for (int a = 0;a<8;a++) { for (int b =0;b<8;b++) cout << brdray [a][b] cout<
Last edited on
It works wich is fantastic and thank you...but i dont understand it yet, i will mark as solved when i do.
You are welcome :D, but firstly you must understand how nested for-loop works
 ``123456789`` ``````for(int i=0; i<5; i++) { for(j=0;j<5; j++) { cout<<"*"; } cout<

for every value of i (from 0 to 4), you run through all values of j.

Outer for-loop
Initialization of i=0, condition i<5 is satisfied hence it executes the statements in the loop which is a for-loop

Inner for-loop:
j=0, condition j<5 is satisfied, hence it executes the statement inside the
brace (Note:for single statement , braces are not required)
The statement is to print a *

Now j is incremented j=1 condition j<5 is satisfied, it prints a *.

Now j is incremented j=2 condition j<5 is satisfied, it prints a *.

Now j is incremented j=3 condition j<5 is satisfied, it prints a *.

Now j is incremented j=4 condition j<5 is satisfied, it prints a *.

Now j is incremented j=5 condition j<5 is not satisfied, the control comes
out of the inner for-loop and executes the next statement which is to print
a new line.

We go to the Outer-loop
i is incremented i=2, i<5 is satisfied and again the inner for-loop is executed.. everything is repeated for every value of i <5

Hence the output is
*****
*****
*****
*****

 ``1234567`` ``````for(int i=0; i<5; i++) { for(j=0;j<5; j++) { cout<<"*"<

Incase of this, since printing of * and a newline belongs to one particular statement hence for every * printed a newline is kept

Hope it helps

Last edited on
@Dala Darko (3)

Just 1 small thing - can you use code tags - the <> button on the right.

Good work on your help to the OP. Cheers :=D
Done :D
Topic archived. No new replies allowed.