c++ - tic tac toe board which size is based on user input -


i working on tic tac toe game , need create function creates board based on user input. can 3x3 or bigger have far when run prints memory location.

#include <iostream> #include <stdlib.h> #include <time.h>  using namespace std;  // array creates boeard based on user input int *drawboard(int width, int height) { int* board_data = new int[width * height]; int** board = new int* [width]; (int = 0; < width; ++i)  {     board[i] = board_data + height * i; } return board_data; }       void main() {  int width = 0; int height = 0;   cout << " welcome tic tac toe v1! " << endl; cout << " choose board size, enter width: " << endl; cin >> width; cout << " choose height: " << endl; cin >> height; cout << drawboard << endl; int *board = drawboard(width, height); delete[] board;    system("pause"); 

}

i think this post out lot. seems you're trying declare dynamic 2d array of integers, use virtual 2d array tic tac toe board, right? not quite sure mean drawboard(), here's simple way print grid:

void printgrid(int y, int x) {     (int j = 0; j < y; j++) {         (int = 0; < x; i++) cout << " ---";         cout << endl;         (int = 0; < x; i++) cout << "|   ";         cout << "|" << endl;     }     (int = 0; < x; i++) cout << " ---";     cout << endl; } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -