NEED HELP! Connect 4 game

I need to be able to update player X and O's location on the board. The problem is, the user is able to set the board size in the beginning! So how can I predict a tokens location when the board size can be ANYTHING from 0 - 11 rows and columns!. This is blowing my newbie mind! I made it with arrays. Please feel free to tell me if there is a much easier way to create this game and how to efficiently update x and o's location on the board!

Practice problem:
Write a two-player game of "connect 4" where the user can set the width and height of the
board and each player gets a turn to drop a token into the slot. Display the board using o for one
side, x for the other, and _ to indicate blank spaces.


My source code:
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>
using namespace std;

string X = "X|";
string O = "O|";

class Connect_4{
private:
int height;
int width;
int x;
int o;
string declaration[11][11];
public:
        void declare(){
            do{
            cout << "GAME START SETTINGS:" << endl << endl;
                cout << "Insert height of board (rows): "; cin >> height; cout << endl;
                cout << "Insert width of board (columns): "; cin >> width;
                if(width <= 0 || width > 10 || height <= 0 || height > 10){
                    cout << endl << "Please insert a width & height greater than 0 & less than 11." << endl << endl;
                cin.ignore(); cout << "Press 'enter' to retry "; cin.ignore();
                system("cls");
                }
            }while(width <= 0 || width > 10 || height <= 0 || height > 10);
        declaration[height][width] = "_|";
        system("cls");
        }

        void board(){
        cout << "CONNECT 4" << endl;
        cout << "           ";
        for(int i = 0; i < width; i++){
        cout << (i+1) << "  ";
        }
        cout << endl;
        for(int i = 0; i < height; i++){
            cout << "           ";
        for(int i = 0; i < width; i++){
            cout << declaration[height][width] << ' ';
            }
            cout << endl;
        }
    }
        void game(){
        cout << endl;
        for(int i = 0; i < height * width; i++){
           if(i % 2 == 0){
            cout << endl << "X's turn: " << endl; cout << "Column: "; cin >> x;
           }
           else if( ! (i % 2 == 0) ){
            cout << endl << "O's turn: " << endl; cout << "Column: "; cin >> o;
           }
           system("cls");
           board();
        }
    }

};

int main(){
Connect_4 object;
object.declare();
object.board();
object.game();
}


Here is a link of how it looks in the console:
http://i50.tinypic.com/14b3w2b.png
Topic archived. No new replies allowed.