I need to make a seating chart showing if seats or taken or empty.

Ok so I have a boolean array - seats[15][30]

I need to make a 15 by 30 seating chart, each empty seat will be represented by a # and each full seat will be a *.

I'm wondering if there's a way to cout seats so that it displays a 15 by 30 bunch of #'s, I can't figure out how to do this.

And then I can make it display a # if seats[row][column] is true OR a * if seats[row][column] is false.

is this possible?

Yes it is possible. You are going to need a 2-level nested for loop(a for loop inside a for loop). Then you need an if statement to check for true or false then cout the correct character. If you don't understand that, start with the tutorial or post your code here and explain the errors you are having, and I will be glad to help you better.
Last edited on
Ok thanks a lot!

So I made a function that displays the 15 by 30 seating chart which works fine,
1
2
3
4
5
6
7
8
9
10
11
void seating_chart()
{
     for (int row = 0; row < 15; row++)
     {cout << "\n#";
         for (int col = 0; col < 30; col++)
         {cout << "#";
         }
     }

     
}


But now I want to make it so that full seats appear as *'s so I wrote this code, but now instead of making a 15 by 30 chart it displays one # per line just going straight down. What did I do wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void seating_chart()
{
     for (int row = 0; row < 15; row++)
     {if (seats[row][col] == true)
           {cout << "\n#";
           }
               else {cout << "\n*";
                    }
         for (int col = 0; col < 30; col++)
         {if (seats[row][col] == true)
              {cout << "\n#";
              }
               else {cout << "\n*";
                    }
         }
     }

     
}


Actually for some reason now this code ^ just crashes the program.

Just to be clear , I have global variables: int row; int col; and bool seats[15][30]
Last edited on
Anybody know why that crashes?
It's difficult to say anything without seeing entire code but i guess , it crashes because of 4.th line.
if (seats[row][col] == true)
Have you initialized value of cal before that line?
If not , that might be problem.

I also say that , your code doesn't look good. I mean , make your code more readable.
Like ;
1
2
3
4
5
6
7
8
 
 for (int col = 0; col < 30; col++)
{
  if (seats[row][col] == true)
     cout << "\n#";
  else 
     cout << "\n*";
}


In my opininon this one looks better
Last edited on
Ok you're right thanks, I had to initialize it first. But also I got the chart to appear but it's way wrong. Assuming seats is [1][1] I would want the # at 1,1 to be a *. But as you can see two asterisks appear for some reason, anybody know how I can fix this display? Thanks for help so far.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
###############################
*#*############################
###############################
###############################
###############################
###############################
###############################
###############################
###############################
###############################
###############################
###############################
###############################
###############################
############################### 


Might I propose a different angle of attack?

15*30 = 450. That means that the program will have to print 450 characters, numbered 0-449. To convert the coordinates to the character number, the formula is (y-coordinate)*30 + (x-coordinate). Good luck.

-Albatross
Darn sorry I'm not understanding what you're saying to do , will I be typing that as code?
Let me try to explain myself a bit better.

The number of characters your program will have to print is 15*30 = 450. If you make a single-dimensional array that is 450 characters long and then print out every character from that array one by one, inserting a newline every 30 characters, then that would work as your seating "chart", as far as graphics are concerned.

If you need to change a character and you don't want to use a function for changing the status of one of the seats that looks like
void invertStatus(int seatnumber)
but rather
void invertStatus(int row, int column)
then the formula to translate the coordinate system to the linear system is
seatnumber = row*30 + column;.

This system is a lot easier to manage.

-Albatross
Last edited on
Ok great so I made an array to display the box of #'s and I see that the seatnumber = row*30 + column; formula will pinpoint on which seat to change into a * , but I am not sure how I would go about changing the exact character of the array from a # to a *.

Pretend my array to display #'s is called chart.

Would this work? chart[seatnumber] = "*"
Please post the entire code you have, and i'm sure you will get your answer alot faster ;)
I'd recommend using an array of booleans or integers and storing in them ones and zeroes to indicate seat status. Then you can have an if-else clause in your for loop. The advantage of this system is that while it will be a bit longer to write, it's harder to mess it up.

-Albatross
Let me just say that you are on the right track. The first problem, though, is that your chart is not printing 15x30, it's printing 15x31.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void seating_chart()
{
    // draw the chart
    for( int row = 0; row < 15; ++row )
    {
        // draw a row
        for( int col = 0; col < 30; ++col )
        {
            // check for occupancy
            if( seats[row][col] ) cout << "#";
            else cout << "*";
        }
        // newline
        cout << endl;
    }  
}

Ok thanks a lot for all the replies so far , I'm going to try that out.
Topic archived. No new replies allowed.