### Program skips two functions in my sudoku solver.

Hey. Programming beginner here, so I might not be familiar with the lingo. I was trying to make this sudoku solver and somehow it skips over two functions. I'll explain further after the code:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188`` `````` #include using namespace std; bool sudokusolver(int col, int row); //Tries to solve the sudoku puzzle bool samecol(int row, int sudoku[][9][9], int num); //Determines if there is a conflict along the column bool samerow(int col, int sudoku[][9][9], int num); //Along a row bool samebox(int col, int row, int sudoku[][9][9], int num); //Determines if there is a conflict in the same box void sudokubacktrack(int col, int row, int sudoku[][9][9], int num); //If all solutions fail, goes backwards until a new answer is made int main() { int col=0, row=0; sudokusolver(col,row); return 0; } bool sudokusolver(int col, int row) { int num; num = 1; //Num starts at 1, and goes up to 9 to test possible answer on a spot int sudoku[2][9][9] = {{ { 3, -1, 6, 5, -1, 8, 4, -1, -1 }, //Just the sudoku example { 5, 2, -1, -1, -1, -1, -1, -1, -1 }, { -1, 8, 7, -1, -1, -1, -1, 3, 1 }, { -1, -1, 3, -1, -1, -1, -1, 8, -1 }, { 9, -1, -1, 8, 6, 3, -1, -1, 5 }, { -1, 5, -1, -1, 9, -1, 6, -1, -1 }, { 1, 3, -1, -1, -1, -1, 2, 5, -1 }, { -1, -1, -1, -1, -1, -1, -1, 7, 4 }, { -1, -1, 5, 2, -1, 6, 3, -1, -1 } }}; for (int i = 0; i < 9; i++) { //Determines if the spot on the sudoku was originally a given number, or a blank space for (int j = 0; j < 9; j++) { //So in the case of when we need to backtrack, when the program has reached a spot filled if (sudoku[0][i][j] == -1) { //in spot, it still knows that it was originally blank, and can be changed. sudoku[1][i][j] = 0; //it's a blank spot } else { sudoku[1][i][j] = 1; //it's given } } } if(sudoku[1][col][row] == 1){ cout< 8){ //If col exceeds 8, that means all blanks have been filled in with no errors. for(int i; i < 9; i++){ //Time to print out the fully answered sudoku cout<<"=================="<

Ok, I know that my code may not be the best or most efficient way, but I wanted to try it in a way that I can easily understand. Now, I added a bunch of words to be printed out on the function ssamecol, samerow, and samebox (line 101, 111, and 143) to see what number is being compared to a certain spot on the grid . But the output just shows that the words from the samebox function is only being printed out. Which means that samecol and samerow is being skipped, somehow?

Also, you might have noticed that I called(Is that the correct term) the samecol,samerow, and samebox function (line 57) right before the if(!samecol...). If I removed those three, it wouldn't print the words at all, so I put them there.

And yeah, the output just keeps going on forever, but I wanted to focus on this problem first. Any help will be appreciated!
Last edited on
 Which means that samecol and samerow is being skipped, somehow?

No, it doesn't. It means that the condition under which you print the "words" in those functions is never true.

Inspect lines 99 and 110. What value does i take on initially?