Home > blog > Sudoku Random Generator

Sudoku Random Generator

C++, problems using return?

int main()
{
int Array[3][3][3][3]={0}; // Array is created and all elements are set to 0
int RemoveCells=0;
srand((unsigned)time(NULL)); // Resets the number used in the random number generator to give a new random number each time

SetScreen(); // Sets the Sudoku grid
ArrayAssign(Array); // Assigns Array’s elements a value
ArrayPlacer(Array); // Places the contents of Array into the Sudoku grid
Difficulty(RemoveCells);
SetPuzzleScreen(); // Sets the Sudoku puzzle grid
Hider(Array, RemoveCells); // Randomly hides around 50 cells in the Sudoku puzzle grid

gotoxy(28,48); //This is to move “Press any key to continue” below the Sudoku puzzle grid

return 0;
}

…….

My Difficulty function has RemoveCells passed in, depending on user input RemoveCells becomes 40, 50 or 60. But when I put

return RemoveCells;

at the the end, it doesnt return them, what am I doing wrong? :S
Thank you so much! That was the EXACT problem!!! :D

i don’t know, because you didn’t post the code of Difficulty().

my guess is that it returns the value, but it’s not assigned in your main function. Change the code to this:

RemoveCells=Difficulty(RemoveCells);

then it should work.

Tungle iPhone Application



  1. No comments yet.
  1. September 9th, 2011 at 21:00 | #1
  2. November 6th, 2011 at 17:53 | #2