Can't figure out loop to set all values in boolean_array[15][30] to true!

This is what I came up with but it just crashes when I run it.

Any ideas! Please help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>

using namespace std;

int main()
{
    bool seats[15][30];
    int loop;
    int row = 1;
    int col = 1;
    
    do
    {
      do 
          {
            seats[row][col] = true;
                  row++;
        
          }
            while (row < 15);
                  col++;
    
    
    
    } while (col < 30);
    system ("Pause");
    
}
Last edited on
It should start at 0, not one. Arrays go from 0 to size-1, not 1 to size.
start row/col at zero, not at 1. Remember that arrays are zero based.. ie the first element is [0].

use a for loop instead of a do/while loop. This can be accomplished with a do/while, but it's a little weird.

Your problem is due to 'row' not being reset to zero in the outer loop. This problem will disappear with a properly written for loop.
Can you please show me I tried using a for loop first but I couldn't figure it out.

Cause I have to make 450 different values to true. and every time the row goes to 15 column has to go up by 1.
1
2
3
4
5
6
7
for (int row = 0; row < totalrowsnum; row++)
{
    for (int col = 0; col < totalcolsnum; col++)
    {
        array[row][col] = somevalue;
    }
}

It's a nested for loop. That's all there is to it.
ok nice thanks a lot, so this is correct of me to do?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

using namespace std;

int main()
{
    bool seats[15][30];
   
     for (int row = 0; row < 15; row++)
      {
       for (int col = 0; col < 30; col++)
         {
              seats[row][col] = true;
         }
      }
}
Should work fine.
Topic archived. No new replies allowed.