Code:
class grid
{
private:
unsigned xSize,
ySize,
gridValues;
string gridFile;
int generateRandom(int);
public:
grid()
{
xSize = 1;
ySize = 1;
}
grid(int sizeX, int sizeY)
{
xSize = sizeX;
ySize = sizeY;
cout << xSize << " " << ySize; Displays random numbers
}
void createRandomGrid();
void loadGrid(string);
void displayGrid();
void displayMenu();
};
Code:
int grid::generateRandom(int num)
{ cout << "in generateRandom" << endl;
return 1 + rand() % num; }
void grid::displayGrid()
{
cout << "this function will return the grid as a string" << endl;
cout << "X:" << xSize(Displays 1) << "Y:" << ySize(Displays 1) << endl;
cout << "The area of your grid is " << xSize*ySize << endl;
}
void grid::createRandomGrid()
{
unsigned seed;
seed = time(0);
cout << "in createRandomGrid" << grid::generateRandom(seed) << endl;This works as intended
grid::grid(grid::generateRandom(seed),grid::generateRandom(seed));
}
So what happens is in grid::createRandomGrid the random number comes out ok, and generateRandom is working ok. My xSize and ySize values are being set by the Grid(int sizeX, int sizeY) but as soon as it finishes my createRandomGrid function and moves into displayGrid function the values of xSize and ySize are set to 1.
What am I not doing to keep these values set?
sorry if its confusing