I'm trying to make a program to print out a grid and given x and y co-ordinates change a value in the grid. For example, if the user entered X:0 and Y:0 it would change the value '9' in the image below to a predefined value (in this case I want to change the value 9 to 0).
My question is, is it possible to update the output of the console so that the '0' would override the '9' without printing out the entire grid again. I want to be able to do this multiple times.
If that is not possible, how can I print out the updated grid the way I have implemented this? If I were to put the display grid for loop in a separate function I would need to call the 2d array as a parameter which I'm sure you cannot do.
Here is what I have:
void generateGrid(int diff){
srand(time(NULL));
int arr[maximum][maximum];
for (int i=0;i<diff;i++)
{
for (int j=0;j<diff;j++)
{
arr[i][j] = rand() % 9 + 1;
}
}
cout<<"\n\tPuzzle\n\t";
for(int i=0;i<diff;i++)
{
cout<<i<<" ";
}
cout<<"\n\n";
for(int i=0;i<diff;i++)
{
cout<<i<<"\t";
for(int j=0;j<diff;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<"\n";
}
int x, y;
cout<<"\nEnter x value: ";
cin>>x;
cout<<"Enter y value: ";
cin>>y;
arr[x][y] = 0;
}
Diff refers to the puzzle size (difficulty)
Elsewhere:
int easy = 5;
int medium = 8;
int hard = 10;
int maximum = 10;