Need Help with Arrays, Making Grids

Hello, guys.

I am new to C++ and I am struggling with arrays here. I am trying to build the connect four game and thought writing this program would be a fun and interesting way to get me to understand C++. Right now, I am trying to set up a 7x6 grid of boxes. However, when it's time to run the program, the boxes appear to go down one single column. Can someone take a look for this and give me some tips, pointers, help? Also, the end result also gives me a 7x6 grid of 0's below that huge column of boxes. What's the deal with that? Is it the program actually returning the NULL? I thought NULL wouldn't return something like that? I have been working on this for quite a long time and some of my attempts to find a solution on google have failed. Thanks a lot in advance!

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#define WIDTH 3
#define HEIGHT 3

using namespace std;
void buildFramework();
int boxFramework();

int main ()
{
    cout << "Welcome to Connect Four!" << endl;
    buildFramework();
    cout << endl;
    
    return 0;
}

void buildFramework()
{
    int i, j;
    int FRAMEWORK[6][7];
    
    for (i=0; i < 6; i++){
        for (j=0; j<7; j++){
            FRAMEWORK[i][j] = boxFramework();
        }
    }
    for (i=0; i<6; i++){
        for (j=0; j<7; j++){
            cout << FRAMEWORK[i][j] << " ";
        }
        cout << endl;
       
    }

}
int boxFramework()
{
    int m;

    cout << " - - - ";
    cout << endl;
    for ( m=0; m< 3; m++){
        cout << "|     |";
        cout << endl;
    }
    
    cout << " - - - " << endl;
    
    return NULL;
}
closed account (2b5z8vqX)

Also, the end result also gives me a 7x6 grid of 0's below that huge column of boxes. What's the deal with that? Is it the program actually returning the NULL?

The function 'boxFramework' is actually returning NULL (which is equivalent to 0), so every element accessed in the first loop within the 'buildFramework' function will be assigned to 0. They will then be wrote to the standard output stream with a space in the following loop.


However, when it's time to run the program, the boxes appear to go down one single column.

That's because the data was wrote in such a way that the boxes would be going down a single column.

Writing games on the command-line that write characters meant to represent objects in this way (the connect four board) should instead be done with a graphics library.
Topic archived. No new replies allowed.