problems with sudoku solver function

Can someone please help me to know how I can fix my code to be able to solve a sudoku board. I know it's long but I really need the help. I suspect the problem is in the "for loop" of the solve sudoku function but I don't know how to go about fixing it. Please as simple as possible, as you can tell i'm a novice.

/* Searches the grid to find an entry that is still unassigned. */
bool FindUnassignedLocation(int board[][9], int &row, int &col)
{

for (row = 0; row < 9; row++)
for (col = 0; col < 9; col++)
if (board[row][col] == 0)
{

return true;
}

return false;
}


/**********************************************************************
* Will compute which numbers can go in a specific square
***********************************************************************/
void computeValues(bool possible[], int board[][9], int *r, int *c)
{
for (int i = 0; i < 10; i++)
{
possible[i] = 1;
}

for (int irow = 0; irow < 9; irow++)
{
possible[board[irow][* c]] = 0;
}

for (int icol = 0; icol < 9; icol++)
{
possible[board[* r][icol]] = 0;
}

for (int irow = 0; irow < 3; irow++)
{
for (int icol = 0; icol < 3; icol++)
{
possible[board[* r / 3 * 3 + irow][* c / 3 * 3 + icol]] = 0;
}
}
}


/* assign values to all unassigned locations for Sudoku solution
*/
bool SolveSudoku(int board[][9], bool possible[], int *r, int *c, int &z)
{

int row, col;
computeValues(possible, board, r, c);
if (!FindUnassignedLocation(board, row, col))
{
return true;
}
for (int num = 1; num <= 9; num++)
{

if (possible[num])
{
board[row][col] = num;
if (SolveSudoku(board, possible, r, c, z))
return true;
board[row][col] = 0;
}
}
//cout << "done solving\n";

return false;
}
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) There's a popular urban legend doing the rounds, that C++ coders are telepathic. This is understandable - surely, people as intelligent, attractive, popular, witty, and all-round awesome as us must also have superpowers, right?

Sadly, it's not true. We're not telepathic. We can't read your mind. This means that, if you have a problem, you have to actually tell us what the problem is. Is your code not compiling? Is it crashing? Is it exhibiting some other undesirable or unexpected behaviour?

3) I don't understand why you're passing row and column numbers into computeValues() and SolveSudoku() as pointers. Why are you doing that? You're not changing their values in those functions - and, even if you were, you clearly know how to pass them as references when you need to, as you demonstrate in FindUnassignedLocation().

4) In computeValues() you seem to be doing integer division. Are you certain that you're not getting errors resulting from the rounding that happens in integer division?

5) In SolveSudoku(), you're attempting to use index values of 1 to 9 into your arrays. In C++, array indices start from 0, so you should be using 0 - 8. You're clearly aware of this already, as you do it correctly in other functions.
Topic archived. No new replies allowed.