Sudoku Help

Hey guys, I've posted here before, and the only time I EVER come here is when I've been working on a program for at least 3 hours straight and I end up being stuck. So, our assignment is to make a Sudoku verifier. Not neccessarily to make one that solves a puzzle, but just to check whether or not it actually works (i.e. it follows the rules of sudoku puzzles).

Now, one thing I want to make very clear (if someone decides to help me) is that I DO NOT want just straight code. I'm not looking for the answer. I just need a little guidance so that I can figure it out on my own. I'm no pro programmer or anything (just learned about operator overloading this afternoon), but everything you see in my code, I believe I have a good understanding of. Anyway, here is my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "Verifier.h"
#include <iomanip>
#include <iostream>
#include <fstream>
#include <stdlib.h>

using namespace std;

Verifier::Verifier() {
        sudoku[numRows][numCols] = { 0 };
        }
        
void Verifier::readGrid( const char* puzzle ) {
        
ifstream inFile;
inFile.open(puzzle, ios::binary);
        
if (inFile.fail()) {
        std::cout << "File did not open";
        exit (1);  
        }
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
inFile >> sudoku[i][j];

inFile.close();
        
}
        
void Verifier::printGrid() {
        
for (int nRow = 0; nRow < 9; nRow++){
for (int nCol = 0; nCol < 9; nCol++){
        cout << sudoku[nRow][nCol] << " ";
        }
cout << endl;
       }
}

bool Verifier::verifySolution() {

bool correct = false;

//for (int x = 0; x < 3; x++) { was going to go for a "3x3" and then goto the
//next "3x3", but I'm not exactly sure how to go about that just yet.
for (int row = 0; row < 9; row++) {
        correct = false;
for (int col = 0; col < 9; col++) {
        if (sudoku[row][col] == sudoku[row][col+1])
        return false;
        else
        correct = true;
}
        //}
}
return correct;
}


Thank you again if anyone plans to help. Just looking for some help. Everything else actually works fine. It prints out the numbers from the file and my driver program is fine. The only issue is the actual verifier. It works for the first puzzle, then calls everything else incorrect.
At first I thought you were trolling me, but I looked through this and this is actually very helpful. Thanks a lot man. Still open for help if anyone can. Pseudo code would be nice haha.
1
2
3
Verifier::Verifier() {
        sudoku[numRows][numCols] = { 0 };
        }


This makes me cringe. As I'm sure you know, valid indices for an array are 0 to array_size-1. I assume numRows and numCols are constants indicating the number of rows and columns in the (presumably class) variable sudoku, so valid indices for rows would be 0 to numRows-1 and for columns would be 0 to numCols-1. If those assumptions are true, you clobber memory you don't own here. If your intention was to initialize the array to all-zero values, that's not what's happening.

Yes they are constants.

Both numRows and numCols = 9. I figured that by doing this, I'm setting that number of possible numbers to 0 (so setting all 9 possible values to 0.
sudoku[0][0] through sudoku[8][8]). But if that's incorrect, I'll look up what I'm doing wrong here. I think I read about initializing multi-dimensional arrays on this website, but I guess I read wrong haha. Thanks for pointing it out.
Topic archived. No new replies allowed.