Moving through an array one step at a time

This is a discussion on Moving through an array one step at a time within the C++ Programming forums, part of the General Programming Boards category; Hi Everyone
I'm having a real issue with my array. I am currently doing an exercise for a chapter on ...

Moving through an array one step at a time

Hi Everyone

I'm having a real issue with my array. I am currently doing an exercise for a chapter on arrays.

I have initialised the bool array, and all the elements are set to false.

I need to go through the array and only change one of the false elements to true each time, so if a false element is found and turned to true; the loop needs to stop and continue once more input is received.

I have tried several different ways to do this but none seem to work, does anyone have any suggestions?

Edit: Okay so you did. I now suggest you show the definition of SeatsArray. I'm curious as to why you are intialising 10 items (without a loop) and then only accessing 5 items later in a loop.
You also need to fix your indentation so it is not misleading where the loop ends etc.

Here you go but this isn't finished, I am just trying to get this part to work correctly.
I'm sorry if it's a really poor attempt.

OK, well, you originally said:

I need to go through the array and only change one of the false elements to true each time, so if a false element is found and turned to true; the loop needs to stop and continue once more input is received.

There are a couple of things to note about the way you put this problem. First, think about how the input relates to the logic of the program. If you have to continue a loop as long as there is input, I would think that input somehow controls the loop. If the input is a seat number, then you would check if the seat is available and give that person a seat if it is, or ask them where else they should sit. You have to do that until everyone has a place to sit.

So:

Code:

while there is input available:
check if there are seats available:
if not, break
else:
ask for a seat
check if that seat is available
if it is, seat the person
if not, repeat