essentially i'm working on a project to make a sudoku game and then check for errors. I'm at the final steps and can't figure out how to do two things
1) How would I write a piece of code to check each row (or each column) to equal 45?
for example, my sudoku example is below:
1 2 3 4 5 6 7 8 9
|
4 3 5 2 6 9 7 8 1
6 8 2 5 7 1 4 9 3
1 9 7 8 3 4 5 6 2
8 2 6 1 9 5 3 4 7
3 7 4 6 8 2 9 1 5
9 5 1 7 4 3 6 2 8
5 1 9 3 2 6 8 7 4
2 4 8 9 5 7 1 3 6
7 6 3 4 1 8 2 5 9
|
how would i check if line 1 (4 3 5 2 6 9 7 8 1) was equal to line 2(6 8 2 5 7 1 4 9 3) and if line 2 is equal to line 3(1 9 7 8 3 4 5 6 2) etc etc
my loop to display the array is:
1 2 3 4 5 6 7
|
for(int row=0; row<9; row++)
{
for(int col=0; col<9; col++)
{
cout << game[row][col] << " ";
}
cout << endl;
|
i can either check each line individually to equal 45(each line must equal 45) or check if all the lines are equal to themselves but i'm not sure how to write the code for either.
2) is it possible to check 3x3 arrays in this array? I want to see if each 3x3 box adds up to 45 and 1-9 once and only once.
so in the above sudoku grid somehow check:
4 3 5
6 8 2
1 9 7
then to the left of that block check:
2 6 9
5 7 1
8 3 4
etc etc