seat with array!!! HELP

heey people .. i have problem that i cant solve i hope you help me with it ...

i need to make seats like this :
A B C D
1 * * * *
2 * * * *
3 * * * *
4 * * * *
5 * * * *

i dont understand how to do it with arrays ... honestly i dont get it [arrays thing !!] its complicated thing ....

you dont need to give me the code you can explain it to me BRIEFLY what is the steps to do it ??!! seriously i am f*****d up with arrays !!!
Last edited on
An array is very similar to a mathematical matrix. It's actually only one-dimensional, but it can be simulated to be two dimensional, as it appears that you're looking at it. Basically, you want a two-dimensional array, and you want to have the values populated with your seat numbers.
okay can u give me steps to do it ... what i have to do first ??
lets say
int seats[row][column]
how i fill it with "*" and number!!!
Well, first things first is to match the variable type to what you want to put in it. If you intend to put * in it, then you can't use int. If it's only numbers, then int is acceptable. After that, just make a loop to iterate through each of the elements and put it's position into it's value.
can you give me example for that ??1
1
2
3
4
5
6
7
8
int seats[4][5], seatNum = 1;

for(int i = 0; i < 4; ++i){
    for(int j = 0; j < 5; ++j){
        seats[i][j] = seatNum;
        ++seatNum;
    }
}


Edit: You can change the dimensions any way you want, and like I said, if you want to change the type of variable, you'll have to make some modifications, but this should populate the array.
Last edited on
To get an output like you have above you could do the following:

1
2
3
4
5
6
7
8
9
10
const int columns = 4, rows = 5; //Sets array boundries.  Const is required
char seats[columns ][rows ] = {'*'}; // fills array with * character.

cout << " ABCD";
for (int i = 0; i < rows; i++)
{
  cout << i; // Output row number
  for (int j = 0; j < columns; j++)    cout << seats[i][j]; // Output that star symbol
  cout << endl; // We've finished a row, start a new line.
}
Topic archived. No new replies allowed.