I am working on a tic tac toe game and need to create a function which creates the board based on user input. Can be 3x3 or bigger I have this so far but when I run it prints memory location.
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
// Array which creates boeard based on user input
int *drawboard(int width, int height)
{
int* board_data = new int[width * height];
int** board = new int* [width];
for (int i = 0; i < width; ++i)
{
board[i] = board_data + height * i;
}
return board_data;
}
void main()
{
int width = 0;
int height = 0;
cout << " Welcome to Tic Tac Toe v1! " << endl;
cout << " Choose your board size, enter width: " << endl;
cin >> width;
cout << " Choose your height: " << endl;
cin >> height;
cout << drawboard << endl;
int *board = drawboard(width, height);
delete[] board;
system("pause");
}