Browse Source

Commit 31 code

remotes/origin/Lucas
Lucas Heil 11 months ago
parent
commit
cee1f107fe
  1. 19
      src/main/c/sudoku.c

19
src/main/c/sudoku.c

@ -27,6 +27,7 @@ void turnFunction(int grid[SIZE][SIZE]);
void tipFunction(int grid[SIZE][SIZE]); void tipFunction(int grid[SIZE][SIZE]);
void inputFunction(int grid[SIZE][SIZE]); void inputFunction(int grid[SIZE][SIZE]);
void printGrid(int grid[SIZE][SIZE]); void printGrid(int grid[SIZE][SIZE]);
void doneFunction(int grid[SIZE][SIZE]);
int availableLevels[3][3][SIZE][SIZE] = { int availableLevels[3][3][SIZE][SIZE] = {
@ -320,6 +321,7 @@ void turnFunction(int grid[SIZE][SIZE]) {
printf("1. Tip function\n"); printf("1. Tip function\n");
printf("2. Input function\n"); printf("2. Input function\n");
printf("3. Print Sudoku grid\n"); printf("3. Print Sudoku grid\n");
printf("4. Done function\n");
int action; int action;
@ -347,7 +349,7 @@ void turnFunction(int grid[SIZE][SIZE]) {
printGrid(grid); printGrid(grid);
break; break;
case 4: case 4:
printf("Case 4.\n");
doneFunction(grid);
break; break;
case 5: case 5:
printf("Case 5.\n"); printf("Case 5.\n");
@ -551,6 +553,21 @@ void printGrid(int grid[SIZE][SIZE]) {
} }
} }
void doneFunction(int grid[SIZE][SIZE]) {
printf("\nDone function - Checking if the solution is correct...\n");
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
if (grid[i][j] != solutionLevels[difficulty - 1][selected_level - 1][i][j]) {
printf("Incorrect solution. Keep trying!\n");
return;
}
}
}
printf("Congratulations! Sudoku is solved correctly.\n");
}
int main(){ int main(){
startSudoku(); startSudoku();

Loading…
Cancel
Save