sodoku board PLZ HELP

Hey guys ill put the program i have created below in which the professor gave me a 5 out of 20 because she stated this program does not seem to do what was expected(the file you submitted does not compile.)can you please help me
This was the original instructions for my assignment Your assignment is to write a program that verifies a Sudoku board. It should check that each row contains each number exactly once, that each column contains each number exactly once, and that each of the nine 3x3 square segments contain each number exactly once.

Begin by creating a 2D array to store the Sudoku board. Then populate all 9x9 elements of the array.

Your program does not need to get input from the user.
Part 1:
Begin by writing code to verify
• The first row
• The first column
• The upper left 3x3 square.
Hint: begin by writing code to display the upper left 3x3 square.
Part 2:
Then, write a separate function for each of these tasks:
• verify row i, where i is the row number.
• verify column i, where i is the column number.
• verify a 3x3 square beginning at row i and column j,

Each of these functions should return a Boolean value to indicate if the verification succeeded or failed. Your functions should not use global variables. Each function should be passed the information it needs as parameters. Call these functions from within loops, so your code will be much more concise! Make sure to test your program with both valid and different types of invalid boards


#include <stdio.h>
#define UNASSIGNED 0

#define N 9
bool FindUnassignedLocation(int grid[N][N], int &row, int &col);
bool isSafe(int grid[N][N], int row, int col, int num);


bool SudokuMain(int grid[N][N])
{
int row, col;


if (!FindUnassignedLocation(grid, row, col))
return true;

for (int num = 1; num <= 9; num++)
{

if (isSafe(grid, row, col, num))
{

grid[row][col] = num;


if (SudokuMain(grid))
return true;


grid[row][col] = UNASSIGNED;
}
}
return false;


bool FindUnassignedLocation(int grid[N][N], int &row, int &col)
{
for (row = 0; row < N; row++)
for (col = 0; col < N; col++)
if (grid[row][col] == UNASSIGNED)
return true;
return false;
}


bool UsedInRow(int grid[N][N], int row, int num)
{
for (int col = 0; col < N; col++)
if (grid[row][col] == num)
return true;
return false;
}


bool UsedInCol(int grid[N][N], int col, int num)
{
for (int row = 0; row < N; row++)
if (grid[row][col] == num)
return true;
return false;
}


bool UsedInBox(int grid[N][N], int boxStartRow, int boxStartCol, int num)
{
for (int row = 0; row < 3; row++)
for (int col = 0; col < 3; col++)
if (grid[row+boxStartRow][col+boxStartCol] == num)
return true;
return false;
}


bool isSafe(int grid[N][N], int row, int col, int num)
{

return !UsedInRow(grid, row, num) &&
!UsedInCol(grid, col, num) &&
!UsedInBox(grid, row - row%3 , col - col%3, num);
}


void printGrid(int grid[N][N])
{
for (int row = 0; row < N; row++)
{
for (int col = 0; col < N; col++)
printf("%2d", grid[row][col]);
printf("n");
}
}


int main()
{

int grid[N][N] = {{3, 0, 6, 5, 0, 8, 4, 0, 0},
{5, 2, 0, 0, 0, 0, 0, 0, 0},
{0, 8, 7, 0, 0, 0, 0, 3, 1},
{0, 0, 3, 0, 1, 0, 0, 8, 0},
{9, 0, 0, 8, 6, 3, 0, 0, 5},
{0, 5, 0, 0, 9, 0, 6, 0, 0},
{1, 3, 0, 0, 0, 0, 2, 5, 0},
{0, 0, 0, 0, 0, 0, 0, 7, 4},
{0, 0, 5, 2, 0, 6, 3, 0, 0}};
if (SudokuMain(grid) == true)
printGrid(grid);
else
printf("No solution exists");
return 0;
}
There is a closing brace } missing at the end of your SudokuMain function.
Why didn't you compile the program before you submitted it.
Last edited on
Topic archived. No new replies allowed.