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.
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?
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*";
}
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.
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.
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;.
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 *.
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.