Arrays questions

So I searched everywhere and posting a new subject is always my last option. But I'm working on this program but I cannot figure this out for the life of me. I need an array of 7 rows of 4 columns. the first column are numbers from 1-7. The second column is all "A"'s. The second all "B"'s and the third all "C"'s.

this is my code for the array.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  int seats[7][4] =
    
    {   {1, 'A', 'B', 'C'},
        {2, 'A', 'B', 'C'},
        {3, 'A', 'B', 'C'},
        {4, 'A', 'B', 'C'},
        {5, 'A', 'B', 'C'},
        {6, 'A', 'B', 'C'},
        {7, 'A', 'B', 'C'}
        
        
      
        };      
        




for some reason when i print it out its
a. not as a table. it just prints out as one big line.

and

b. it gives me the ascii values for the letters.

here is my loop to print out the table.

1
2
3
4
5
6
7
  for (int i = 0; i < 7; i++)
          
               for (int j = 0; j < 4; j++)
               
             cout << seats[i][j]<< " "; 
 



any help would be appreciated.
thanks in advanced.
first off, you have an array of ints you want chars if you don't want the ascii value.

Second, Of course it prints off as one big line, you didn't specify anything else =)

I would recommend putting a cout << endl; or "\n" after the second for loop within the first for loop.

edit: haha beat ya veltas!
Last edited on
Because you're outputting an 'int' the output will be the numerical value for the character entered. Change the type to 'char'.

The reason it prints one line is because you've programmed it to.

Try:

1
2
3
4
5
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 4; j++) cout << seats[i][j]<< " "; 
cout << endl;
}


edit: blast!
Last edited on
wow that was so easy. i cannot believe i didn't get that. I've been working on it for like an hour already.lol Thanks you guys.
Topic archived. No new replies allowed.