Array Printing a Hex

I posted this on StackOverflow and got a response that basically said I am not worthy. I really want to learn, so I'm hoping someone will give me some good feedback here:



I'm pretty new to C++, have only coded for one class so far so I don't really know what's wrong here. I met with a couple of tutors earlier who also couldn't figure out why this code is printing a memory location instead of the 2d array I'm looking for.

What I want it to do is print 30x15 asterisks...it's for a seating chart program.

Here's the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  #include <iostream>
#include <iomanip>

using namespace std;

int main  ()

{

const int SEATS=30;
const int ROWS=15;
const char TAKEN='*';
const char AVAILABLE='#';
char display [ROWS][SEATS];

{

for (int j=0; j<ROWS; j++)


    for (int k=0; k<SEATS; k++)



    display [j][k]=TAKEN;
    cout<<display;
}

    return 0;
}


Many thanks in advance!
Line 26, you are printing the address of the first element of your array instead of each element's contents.

See how you are accessing each element at line 25 for every iteration of your two for loops?

Line 25 makes sure that every element is assigned the TAKEN value.
That makes sense...thank you, that clarifies a lot for me!! Makes so much sense, I can't believe how much time I spent on that.

I edited the code to this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

#include <iostream>
#include <iomanip>

using namespace std;

int main  ()

{
	
const int SEATS=30;
const int ROWS=15;
const char TAKEN='*';
const char AVAILABLE='#';
char display [ROWS][SEATS];
{

for (int j=0; j<ROWS; j++)
	
	for (int k=0; k<SEATS; k++)
	
	display [j][k]=TAKEN;
	
	{
	 for (int j=0; j<ROWS; j++)
	
		for (int k=0; k<SEATS; k++)
		
		cout<<""<<display[j][k];

	}

}
	
	return 0;
}


It now prints my asterisks, but not in the 15x30 array I'm looking for. Looks like it's probably the correct number of asterisks (I didn't count them but it seems right.) Is there any insight you can give me about this? Thank you so much again!!!
You almost had it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

int main()
{
   const size_t SEATS   { 30 };
   const size_t ROWS    { 15 };
   const char TAKEN     { '*' };
   const char AVAILABLE { '#' };

   char display[ROWS][SEATS];

   for (size_t rows { }; rows < ROWS; rows++)
   {
      for (size_t seats { }; seats < SEATS; seats++)
      {
         display[rows][seats] = TAKEN;

         std::cout << display[rows][seats] << ' ';
      }
      std::cout << '\n';
   }
}
Thank you so very much!!!
Topic archived. No new replies allowed.