### 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:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667`` ``````#include #include 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.