#include <windows.h>
#include <fstream>
#include <cmath>
#include <iostream>
usingnamespace std;
#define gridsize 9
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void updateGrid();
int getUnknowns();
void getUnchangable();
bool isCorrect(int a, int b);
void resetPossibleValues();
void theSwitchStatement(int &aa, int &ab, HWND &hwnd);
bool anyPossibleValues(int a, int b);
void updateGridWindows();
void clear();
void stealth();
bool checkForErrors();
string charToString(char a[]);
int steps;
double a = 0;
bool cantSolve;
int grid[gridsize][gridsize];
int unchangable[gridsize][gridsize];
int possibleValues[gridsize][gridsize][gridsize];
/* Make the class name into a global variable */
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
//stuff
}
So what I need to do is - on line 7, I define gridsize as 9. What I want to do is allow the user to input the gridsize, but as you can see, some variables need to be global and use the value of gridsize. I could probably use vectors, but it's kind of annoying to rewrite the whole program :/ Is there any way of doing this without rewriting the whole program?
Make the global variables pointers. Then in main, dynamically allocate the memory.
But the question I have for you is, why do all these variables need to be global? If you created a class (say "Solver"), these variables would be data members of the class. The constructor could take the size argument, and you could allocate the grid at construction time.
Actually, you would also want a Grid class (for grid and unchangeable) and PossibleValues class, each of which take grid size as a constructor argument. The Solver class would contain the necessary objects of these types. These classes would facilitate changing the representation of the grid from arrays to vectors when the time comes.