From cee1f107fe2adcbaa2908c84fee7b2ca8cace614 Mon Sep 17 00:00:00 2001 From: Lucas Heil Date: Wed, 7 Feb 2024 17:21:42 +0100 Subject: [PATCH] Commit 31 code --- src/main/c/sudoku.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/c/sudoku.c b/src/main/c/sudoku.c index cc5739c..ef28e84 100644 --- a/src/main/c/sudoku.c +++ b/src/main/c/sudoku.c @@ -27,6 +27,7 @@ void turnFunction(int grid[SIZE][SIZE]); void tipFunction(int grid[SIZE][SIZE]); void inputFunction(int grid[SIZE][SIZE]); void printGrid(int grid[SIZE][SIZE]); +void doneFunction(int grid[SIZE][SIZE]); int availableLevels[3][3][SIZE][SIZE] = { @@ -320,6 +321,7 @@ void turnFunction(int grid[SIZE][SIZE]) { printf("1. Tip function\n"); printf("2. Input function\n"); printf("3. Print Sudoku grid\n"); + printf("4. Done function\n"); int action; @@ -347,7 +349,7 @@ void turnFunction(int grid[SIZE][SIZE]) { printGrid(grid); break; case 4: - printf("Case 4.\n"); + doneFunction(grid); break; case 5: 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(){ startSudoku();