I've got something like 400 lines of code at this point, and I realize that not too many people will be inclined to look at it. Thankfully, the majority of it works swell, and I only need part of it examined. I realize that my use of vectors is not right, and i would love for someone to take a peek at my code to show me what I'm doing wrong. I can provide some guidance about which parts should be looked at, as the code is incomplete and really won't make sense yet to anyone but myself. I'll provide an attachment for anyone kind enough to look.

Functions that need some help are detailed as follows:
1. The return of the RecordValues function, which is called by the FinishBoard function. Currently the function has no return; however, I realize that this

vector<int> sureValues = RecordValues(FinalBoard, i, theRandom)

is inadequate.

I am curious if the CheckCell function is called properly. Additionally, I think the prototypes that have vectors as parameters need to be looked at.

The compiler is telling me that the code

if (CheckCell(sureValues, row, column) == false)

is wrong because "conversion from 'int' to non-scalar type 'std::vect<int, std::allocater<int>' requested."

Thanks for the help

Attachments
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <fstream> // Stream class to write files.
#include <ctype.h> // allows the use of toupper.
#include <vector>  // Used for the final Sudoku board with removed numbers.
using namespace std;

/////////////  Define Function Prototypes //////////////////
int CheckCell(vector<int>& sureValues, int row, int column);
int RecordValues(const int Board[9][9], int row, int column);
void CreateBoard(int Board[9][9]);
void FinishBoard(int Board[9][9], int difficulty);
int Difficulty();
void Debug(int Board[9][9], bool BoardStatus[9][9], int row, int column, int BoardTemp);
void WriteFile(int Board[9][9]);
void Display(int Board[9][9]);
void Reset(int Board[9][9], bool BoardStatus[9][9]);
int Random_Number(); //  Used to create random integers.  This will ensure that each Sudoku board is unique.
bool Verify(int Board[9][9], int row, int column); // Determines whether the values within a given cell are valid or not.

///////////// Main ////////////////
int main()
{
    int Board[9][9];
    CreateBoard(Board); 
    int difficulty = Difficulty();
    WriteFile(Board);
    Display(Board);
    FinishBoard(Board, difficulty);  
    cin.ignore();
    return 0;
}
void FinishBoard(int FinalBoard[9][9], int difficulty) // scans columns and rows to determine if values within a cell can both be determined by humans and have a single solution.
{
     if (difficulty >= 0) // Easy
     {
          for (int i = 0; i <= 8; i ++) // makes sure that one cell will be blank in each row.
          {
               int theRandom = Random_Number();
               FinalBoard [i][theRandom];  // The cell whose value will be tested to see it can be removed.
               vector<int> sureValues = RecordValues(FinalBoard, i, theRandom)  // i functions as the row while theRandom functions as the column.
               if (CheckCell(sureValues, row, column) == false)
               {
                    FinalBoard [i][theRandom] = " ";
               }
          }
     }               
     if (difficulty >= 1) // Intermediate
     {
          for (int i = 0; i <= 8; i ++) // makes sure that one cell will be blank in each row.
          {
               int theRandom = Random_Number();
               FinalBoard [i][theRandom]; // The cell whose value will be tested to see it can be removed.
          }
     }
     if (difficulty >= 2) //  Hard
     {
          for (int i = 0; i <= 8; i ++) // makes sure that one cell will be blank in each row.
          {
               int theRandom = Random_Number(); 
               FinalBoard [i][theRandom]; // The cell whose value will be tested to see it can be removed.
          }
     }
}
int CheckCell(vector<int>& sureValues, int row, int column)
{
;
}
int RecordValues(const int Board[9][9], int row, int column);
{
     vector<int> sureValues;
     for (i = 0; i <= 8; i++) // record row values.
     {
          if ( i != column && Board[row][i] != " ")
          {
               sureValues.pushback(Board[row][i]);
          }
     }
     for (i = 0; i <= 8; i++) // record column values.
     {
          if ( i != row && Board[i][column] != " ")
          {
               sureValues.pushback(Board[i][column]);
          }
     }
     if (column%3 == 0 && row%3 == 0) // Record cell values.
     {
        if (Board [row+1][column+1]) != " ")
        { sureValues.pushback(Board [row+1][column+1]) }
        if (Board [row+2][column+1] != " ") 
        { sureValues.pushback (Board [row+2][column+1]) }
        if (Board [row+1][column+2] != " ")
        { sureValues.pushback(Board [row+1][column+2]) }
        if (Board [row+2][column+2] != " ")
        { sureValues.pushback(Board [row+2][column+2]) }
     }
     if (column%3 == 1 && row%3 == 0)
     {
        if (Board [row+1][column-1]) != " ")
        { sureValues.pushback(Board [row+1][column-1]]) }
        if (Board[row+2][column-1]] != " ") 
        { sureValues.pushback (Board[row+2][column-1]) }
        if (Board [row+1][column+1] != " ")
        { sureValues.pushback(Board [row+1][column+1]) }
        if (Board [row+2][column+1] != " ")
        { sureValues.pushback(Board [row+2][column+1]) }
     }
     if (column%3 == 2 && row%3 == 0)
     {
        if (Board [row+1][column-1]) != " ")
        { sureValues.pushback(Board [row+1][column-1]) }
        if (Board [row+2][column-1] != " ") 
        { sureValues.pushback (Board [row+2][column-1]) }
        if (Board [row+1][column-2] != " ")
        { sureValues.pushback(Board [row+1][column-2]) }
        if (Board [row+2][column-2] != " ")
        { sureValues.pushback(Board [row+2][column-2]) }
     }
     if (column%3 == 0 && row%3 == 1)
     {
        if (Board [row-1][column+1]) != " ")
        { sureValues.pushback(Board [row-1][column+1]) }
        if (Board [row-1][column+2] != " ") 
        { sureValues.pushback (Board [row-1][column+2]) }
        if (Board [row+1][column+1] != " ")
        { sureValues.pushback(Board [row+1][column+1]) }
        if (Board [row+1][column+2]) != " ")
        { sureValues.pushback(Board [row+1][column+2]) } 
     }
     if (column%3 == 1 && row%3 == 1)
     {
        if (Board [row-1][column-1]) != " ")
        { sureValues.pushback(Board [row-1][column-1]) }
        if (Board[row+1][column-1] != " ") 
        { sureValues.pushback (Board[row+1][column-1]) }
        if (Board [row-1][column+1] != " ")
        { sureValues.pushback(Board [row-1][column+1]) }
        if (Board [row+1][column+1] != " ")
        { sureValues.pushback(Board [row+1][column+1]) }
     }
     if (column%3 == 2 && row%3 == 1)
     {
        if (Board [row-1][column-2]) != " ")
        { sureValues.pushback(Board [row-1][column-2]) }
        if (Board [row-1][column-1] != " ") 
        { sureValues.pushback (Board [row-1][column-1]) }
        if (Board [row+1][column-2] != " ")
        { sureValues.pushback(Board [row+1][column-2]) }
        if (Board [row+1][column-1] != " ")
        { sureValues.pushback(Board [row+1][column-1]) }
     }
     if (column%3 == 0 && row%3 == 2)
     {
        if (Board [row-1][column+1]) != " ")
        { sureValues.pushback(Board [row-1][column+1]) }
        if (Board [row-2][column+1] != " ") 
        { sureValues.pushback (Board [row-2][column+1]) }
        if (Board [row-1][column+2] != " ")
        { sureValues.pushback(Board [row-1][column+2]) }
        if (Board [row-2][column+2] != " ")
        { sureValues.pushback(Board [row-2][column+2]) }
     }
     if (column%3 == 1 && row%3 == 2) 
     {
        if (Board [row-1][column-1]) != " ")
        { sureValues.pushback(Board [row-1][column-1]) }
        if (Board [row-2][column-1] != " ") 
        { sureValues.pushback (Board [row-2][column-1]) }
        if (Board [row-1][column+1] != " ")
        { sureValues.pushback(Board [row-1][column+1]) }
        if (Board [row-2][column+1] != " ")
        { sureValues.pushback(Board [row-2][column+1]) }
     }
     if (column%3 == 2 && row%3 == 2)
     {
        if (Board [row-2][column-2]) != " ")
        { sureValues.pushback(Board [row-2][column-2]) }
        if (Board [row-1][column-2] != " ") 
        { sureValues.pushback (Board [row-1][column-2]) }
        if (Board [row-2][column-1] != " ")
        { sureValues.pushback(Board [row-2][column-1]) }
        if (Board [row-1][column-1] != " ")
        { sureValues.pushback(Board [row-1][column-1]) }
     }
}
void CreateBoard(int Board[9][9])
{
    int row = 0;
    int column = 0;
    bool BoardStatus [9][9];  
    int BoardTemp;
    Reset(Board, BoardStatus);
    for (row = 0; row <= 8; row++) 
    {
        for (column = 0; column <= 8; column++)
        {
            while (BoardStatus [row][column] == false)
            {
               if (Board [row][column] == -1)
               {
                 Board [row][column] = Random_Number();  // a random number is placed inside every cell before the validation process begins in order to randomize each puzzle.
                 BoardTemp = Board [row][column];
               }
               BoardStatus [row][column] = Verify(Board, row, column);
               if (BoardStatus [row][column] == false)
               {
                     Board [row][column] = Board[row][column]+ 1;
                     if (Board [row][column] == 10) // A value inside a cell cannot be greater than 9.
                     {
                          Board[row][column] = 1;
                     }
                     if (BoardTemp == Board[row][column] )
                     {
                          Reset(Board, BoardStatus);
                          row = 0;
                          column = 0;     
                     }
               }            
            }
        }
    }
}
int Difficulty()
{
    cout << "Choose a difficulty among Easy, Intermediate, and Hard.";
    string x;
    int difficulty;
    cin >> x;
    for (int i =0; i <= x.size(); i++)
    { x[i] = toupper(x[i]); }
    if (x == "EASY" )
    { difficulty = 0; }
    if (x == "INTERMEDIATE" ) 
    { difficulty = 1; }
    if (x == "HARD" )
    { difficulty = 2; }
    return difficulty;
}
    
void WriteFile(int Board[9][9])
{
     ofstream SudokuBoard;
     SudokuBoard.open ("1.txt", fstream::app);
     for (int row = 0; row <= 8; row++)
     {
          SudokuBoard << endl << "----------------------" << endl;
          if ( row == 3 || row == 6)
          {
               SudokuBoard << "----------------------" << endl;
          }
          for (int column = 0; column <= 8; column++)
          {
              SudokuBoard << Board[row][column] << "|";  // prints horizontally.
              if (column == 2 || column == 5)
               {
                    SudokuBoard << "| ";
               }
          }
     }
     SudokuBoard << endl  << endl;
     SudokuBoard.close();
}
void Debug (int Board[9][9], bool BoardStatus[9][9], int row, int column, int BoardTemp)
{
     Display(Board);
     cout << endl;
     cout << "column"

I'm not going to solve every problem for you ('cause there's a lot, sorry). But here are a few:

line 45: 1vector<int> sureValues = RecordValues(FinalBoard, i, theRandom)1

You missed a semicolon at the end. But more important (..), you can't assign a value to a vector like that. Recordvalues() returns an int, and you're trying to make the vector that value... Compiler doesn't like that. Perhaps you meant something like:

   vector<int> sureValues; 
   sureValues.push_back( RecordValues(FinalBoard, i, theRandom)); 

line 48:

if (CheckCell(sureValues, row, column) == false) variables 'row' and column aren't defined in the function FinishBoard

line 49:

FinalBoard [i][theRandom] = " ";

Finalboard is an array of ints. So you can't put a string ( " " == a string) in it.

line 71:

Function CheckCell is supposed to return an int but doesn't

line 75-76:

int RecordValues(const int Board[9][9], int row, int column);  <--- remove this
{

Remove the semicolon after lone 75, or the function won't do anything :)

In function RecordValues:

'i' is undefined, put a int i =0; at the beginning of the function

line 78:

if ( i != column && Board[row][i] != " ")

Board is an array of ints. There will never be a "space" in it. I don't know what you're trying to do here.

This errors occurs about 50 times in this function

Overall:

vector.pushback

pushback isn't a member of std::vector. Try changing it to : push_back. Takes care of another 50 errors :)

In Recordvalues:

    if (Board [row+1][column+1] != 0)
    { sureValues.push_back(Board [row+1][column+1]) ; <--add semicolon!! }

Do this everywhere, and another 100 errors are gone....

I'm going to stop now. Please note that I didn't look at your logic, so even if this program finally compiles, there's a good change that it still won't work... But you can come back here and we'll have another look ;)

If I can give you a suggestion:
Don't try to code it all at once and then compile it. Break your problem down in to little pieces and try solving them one at a time. That way you won't have to solve hundreds of syntax-errors at the last minute :)

[edit]

Needing someone really nice to look at my code

Oh...In that case, disregard by post and go look for someone nice ;)

Edited 3 Years Ago by Dani: Formatting fixed

Before I get down into the nitty-gritty and really start trying to fix all of my hundreds of syntax errors, I have a quick question about the storing of " " in an array of integers.

In the other thread http://www.daniweb.com/forums/thread129059.html,
we were talking about the difference between char and int. I was told that ultimately type determines how cout chooses to display a given value. furthermore, when I store a " " in int, isn't it simply stored as a number? Can't I tell cout when it sees this number to display a space instead? Will the compiler generate an error when I try to store a " " inside an int?

> Can't I tell cout when it sees this number to display a space instead?
Yes, just cast it as a char.

> Will the compiler generate an error when I try to store a " " inside an int?
Yes, but only because you need to specify a char with single quotes, not double quotes: ' '. If you use a character literal, everything is fine:

int foo = ' '; // OK!

std::cout << (char)foo << '\n'; // Print as a character

alright. fixed a crapload of errors. At least 100 of them. Thank goodness for Microsoft word's replace feature.

So I've solved all of my issues minus 1. On line 187,

return sureValues;

causes the error cannot convert 'std::vector<int, std::allocator<int> >' to 'int' in return. I've got a feeling that this error has to do something with my declaration of the function, which looks like this

int RecordValues(const int Board[9][9], int row, int column)

. Other than this one, I'm good to go.

After this i hope to implement some sort of backtracking algorithm to dramatically decrease the Sudoku board creation time.

Thanks for the help. By the way, should I be returning this vector as a reference maybe? Or is that not possible if the vector is created in a function, because the variable would become out of scope?

All of the redone code is attached below.

EDIT: oo, by the way, I wanted to ask a question about this line

vector<int> sureValues;
      sureValues.push_back( RecordValues(FinalBoard, i, theRandom));

So, I'm guessing that since the return of RecordValues is a vector that I am able to push_back the contents of an entire vector into a new vector.

Attachments
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <fstream> // Stream class to write files.
#include <ctype.h> // allows the use of toupper.
#include <vector>  // Used for the final Sudoku board with removed numbers.
using namespace std;

/////////////  Define Function Prototypes //////////////////
int CheckCell(vector<int> &sureValues, int row, int column);
int RecordValues(const int Board[9][9], int row, int column);
void CreateBoard(int Board[9][9]);
void FinishBoard(int Board[9][9], int difficulty);
int Difficulty();
void Debug(int Board[9][9], bool BoardStatus[9][9], int row, int column, int BoardTemp);
void WriteFile(int Board[9][9]);
void Display(int Board[9][9]);
void Reset(int Board[9][9], bool BoardStatus[9][9]);
int Random_Number(); //  Used to create random integers.  This will ensure that each Sudoku board is unique.
bool Verify(int Board[9][9], int row, int column); // Determines whether the values within a given cell are valid or not.

///////////// Main ////////////////
int main()
{
    int Board[9][9];
    CreateBoard(Board); 
    int difficulty = Difficulty();
    WriteFile(Board);
    Display(Board);
    FinishBoard(Board, difficulty);  
    cin.ignore();
    return 0;
}
void FinishBoard(int FinalBoard[9][9], int difficulty) // scans columns and rows to determine if values within a cell can both be determined by humans and have a single solution.
{
     if (difficulty >= 0) // Easy
     {
          for (int i = 0; i <= 8; i ++) // makes sure that one cell will be blank in each row.
          {
               int theRandom = Random_Number();
               FinalBoard [i][theRandom];  // The cell whose value will be tested to see it can be removed.
               vector<int> sureValues; 
               sureValues.push_back( RecordValues (FinalBoard, i, theRandom) );  // i functions as the row while theRandom functions as the column.
               if (CheckCell(sureValues, i, theRandom) == false) // again, i functions as the row and theRandom as the column.
               {
                    FinalBoard [i][theRandom] = ' ';
               }
          }
     }               
     if (difficulty >= 1) // Intermediate
     {
          for (int i = 0; i <= 8; i ++) // makes sure that one cell will be blank in each row.
          {
               int theRandom = Random_Number();
               FinalBoard [i][theRandom]; // The cell whose value will be tested to see it can be removed.
          }
     }
     if (difficulty >= 2) //  Hard
     {
          for (int i = 0; i <= 8; i ++) // makes sure that one cell will be blank in each row.
          {
               int theRandom = Random_Number(); 
               FinalBoard [i][theRandom]; // The cell whose value will be tested to see it can be removed.
          }
     }
}
int CheckCell(vector<int>& sureValues, int row, int column)
{
return 0;   ///////////// Work in progress
}
int RecordValues(const int Board[9][9], int row, int column)
{
     vector<int> sureValues;
     for (int i = 0; i <= 8; i++) // record row values.
     {
          if ( i != column && Board[row][i] != ' ')
          {
               sureValues.push_back(Board[row][i]);
          }
     }
     for (int i = 0; i <= 8; i++) // record column values.
     {
          if ( i != row && Board[i][column] != ' ')
          {
               sureValues.push_back(Board[i][column]);
          }
     }
     if (column%3 == 0 && row%3 == 0) // Record cell values.
     {
        if (Board [row+1][column+1] != ' ')
        { sureValues.push_back(Board [row+1][column+1]); }
        if (Board [row+2][column+1] != ' ') 
        { sureValues.push_back (Board [row+2][column+1]); }
        if (Board [row+1][column+2] != ' ')
        { sureValues.push_back(Board [row+1][column+2]); }
        if (Board [row+2][column+2] != ' ')
        { sureValues.push_back(Board [row+2][column+2]); }
     }
     if (column%3 == 1 && row%3 == 0)
     {
        if (Board [row+1][column-1] != ' ')
        { sureValues.push_back(Board [row+1][column-1]); }
        if (Board[row+2][column-1] != ' ') 
        { sureValues.push_back (Board[row+2][column-1]); }
        if (Board [row+1][column+1] != ' ')
        { sureValues.push_back(Board [row+1][column+1]); }
        if (Board [row+2][column+1] != ' ')
        { sureValues.push_back(Board [row+2][column+1]); }
     }
     if (column%3 == 2 && row%3 == 0)
     {
        if (Board [row+1][column-1] != ' ')
        { sureValues.push_back(Board [row+1][column-1]); }
        if (Board [row+2][column-1] != ' ') 
        { sureValues.push_back (Board [row+2][column-1]); }
        if (Board [row+1][column-2] != ' ')
        { sureValues.push_back(Board [row+1][column-2]); }
        if (Board [row+2][column-2] != ' ')
        { sureValues.push_back(Board [row+2][column-2]); }
     }
     if (column%3 == 0 && row%3 == 1)
     {
        if (Board [row-1][column+1] != ' ')
        { sureValues.push_back(Board [row-1][column+1]); }
        if (Board [row-1][column+2] != ' ') 
        { sureValues.push_back (Board [row-1][column+2]); }
        if (Board [row+1][column+1] != ' ')
        { sureValues.push_back(Board [row+1][column+1]); }
        if (Board [row+1][column+2] != ' ')
        { sureValues.push_back(Board [row+1][column+2]); } 
     }
     if (column%3 == 1 && row%3 == 1)
     {
        if (Board [row-1][column-1] != ' ')
        { sureValues.push_back(Board [row-1][column-1]); }
        if (Board [row+1][column-1] != ' ') 
        { sureValues.push_back (Board[row+1][column-1]); }
        if (Board [row-1][column+1] != ' ')
        { sureValues.push_back(Board [row-1][column+1]); }
        if (Board [row+1][column+1] != ' ')
        { sureValues.push_back(Board [row+1][column+1]); }
     }
     if (column%3 == 2 && row%3 == 1)
     {
        if (Board [row-1][column-2] != ' ')
        { sureValues.push_back(Board [row-1][column-2]); }
        if (Board [row-1][column-1] != ' ') 
        { sureValues.push_back (Board [row-1][column-1]); }
        if (Board [row+1][column-2] != ' ')
        { sureValues.push_back(Board [row+1][column-2]); }
        if (Board [row+1][column-1] != ' ')
        { sureValues.push_back(Board [row+1][column-1]); }
     }
     if (column%3 == 0 && row%3 == 2)
     {
        if (Board [row-1][column+1] != ' ')
        { sureValues.push_back(Board [row-1][column+1]); }
        if (Board [row-2][column+1] != ' ') 
        { sureValues.push_back (Board [row-2][column+1]); }
        if (Board [row-1][column+2] != ' ')
        { sureValues.push_back(Board [row-1][column+2]); }
        if (Board [row-2][column+2] != ' ')
        { sureValues.push_back(Board [row-2][column+2]); }
     }
     if (column%3 == 1 && row%3 == 2) 
     {
        if (Board [row-1][column-1] != ' ')
        { sureValues.push_back(Board [row-1][column-1]); }
        if (Board [row-2][column-1] != ' ') 
        { sureValues.push_back (Board [row-2][column-1]); }
        if (Board [row-1][column+1] != ' ')
        { sureValues.push_back(Board [row-1][column+1]); }
        if (Board [row-2][column+1] != ' ')
        { sureValues.push_back(Board [row-2][column+1]); }
     }
     if (column%3 == 2 && row%3 == 2)
     {
        if (Board [row-2][column-2] != ' ')
        { sureValues.push_back(Board [row-2][column-2]); }
        if (Board [row-1][column-2] != ' ') 
        { sureValues.push_back (Board [row-1][column-2]); }
        if (Board [row-2][column-1] != ' ')
        { sureValues.push_back(Board [row-2][column-1]); }
        if (Board [row-1][column-1] != ' ')
        { sureValues.push_back(Board [row-1][column-1]); }
     }
     return sureValues;
}
void CreateBoard(int Board[9][9])
{
    int row = 0;
    int column = 0;
    bool BoardStatus [9][9];  
    int BoardTemp;
    Reset(Board, BoardStatus);
    for (row = 0; row <= 8; row++) 
    {
        for (column = 0; column <= 8; column++)
        {
            while (BoardStatus [row][column] == false)
            {
               if (Board [row][column] == -1)
               {
                 Board [row][column] = Random_Number();  // a random number is placed inside every cell before the validation process begins in order to randomize each puzzle.
                 BoardTemp = Board [row][column];
               }
               BoardStatus [row][column] = Verify(Board, row, column);
               if (BoardStatus [row][column] == false)
               {
                     Board [row][column] = Board[row][column]+ 1;
                     if (Board [row][column] == 10) // A value inside a cell cannot be greater than 9.
                     {
                          Board[row][column] = 1;
                     }
                     if (BoardTemp == Board[row][column] )
                     {
                          Reset(Board, BoardStatus);
                          row = 0;
                          column = 0;     
                     }
               }            
            }
        }
    }
}
int Difficulty()
{
    cout << "Choose a difficulty among Easy, Intermediate, and Hard.";
    string x;
    int difficulty;
    cin >> x;
    for (int i =0; i <= x.size(); i++)
    { x[i] = toupper(x[i]); }
    if (x == "EASY" )
    { difficulty = 0; }
    if (x == "INTERMEDIATE" ) 
    { difficulty = 1; }
    if (x == "HARD" )
    { difficulty = 2; }
    return difficulty;
}
    
void WriteFile(int Board[9][9])
{
     ofstream SudokuBoard;
     SudokuBoard.open ("1.txt", fstream::app);
     for (int row = 0; row <= 8; row++)
     {
          SudokuBoard << endl << "----------------------" << endl;
          if ( row == 3 || row == 6)
          {
               SudokuBoard << "----------------------" << endl;
          }
          for (int column = 0; column <= 8; column++)
          {
              SudokuBoard << Board[row][column] << "|";  // prints horizontally.
              if (column == 2 || column == 5)
               {
                    SudokuBoard << "| ";
               }

I've resolved nearly all of my issues. The code compiles; however, it displays the wrong answer. I've narrowed the problem down to one of two functions. Likely the problem has to do with the vector sureValues inside them both or with my use of the find() function. If anyone can give me their input, it would be much appreciated. Thank you for your help.

By the way, 90% of the RecordValues() function can be ignored. It has numerous duplicate statements with a few values changed. if there is a problem in one of them, the problem exists in them all.

bool CheckCell(vector<int>& sureValues, int row, int column) // Ensures that after a cell has been removed a board both remains solvable by humans and possesses only one solution. 
{
     for (int i = 0; i <=8; i++)
     {
          if (find(sureValues.begin(), sureValues.end(), i) == sureValues.end())
          {
               return false;
          }
     }
     return true;
}
vector<int> RecordValues(const int finalBoard[9][9], int row, int column)
{
     vector<int> sureValues;
     for (int i = 0; i <= 8; i++) // record row values.
     {
          if ( i != column && finalBoard[row][i] != ' ')
          {
               sureValues.push_back(finalBoard[row][i]);
          }
     }
     for (int i = 0; i <= 8; i++) // record column values.
     {
          if ( i != row && finalBoard[i][column] != ' ')
          {
               sureValues.push_back(finalBoard[i][column]);
          }
     }
     if (column%3 == 0 && row%3 == 0) // Record cell values.
     {
        if (finalBoard [row+1][column+1] != ' ')
        { sureValues.push_back(finalBoard [row+1][column+1]); }
        if (finalBoard [row+2][column+1] != ' ') 
        { sureValues.push_back (finalBoard [row+2][column+1]); }
        if (finalBoard [row+1][column+2] != ' ')
        { sureValues.push_back(finalBoard [row+1][column+2]); }
        if (finalBoard [row+2][column+2] != ' ')
        { sureValues.push_back(finalBoard [row+2][column+2]); }
     }
     if (column%3 == 1 && row%3 == 0)
     {
        if (finalBoard [row+1][column-1] != ' ')
        { sureValues.push_back(finalBoard [row+1][column-1]); }
        if (finalBoard[row+2][column-1] != ' ') 
        { sureValues.push_back (finalBoard[row+2][column-1]); }
        if (finalBoard [row+1][column+1] != ' ')
        { sureValues.push_back(finalBoard [row+1][column+1]); }
        if (finalBoard [row+2][column+1] != ' ')
        { sureValues.push_back(finalBoard [row+2][column+1]); }
     }
     if (column%3 == 2 && row%3 == 0)
     {
        if (finalBoard [row+1][column-1] != ' ')
        { sureValues.push_back(finalBoard [row+1][column-1]); }
        if (finalBoard [row+2][column-1] != ' ') 
        { sureValues.push_back (finalBoard [row+2][column-1]); }
        if (finalBoard [row+1][column-2] != ' ')
        { sureValues.push_back(finalBoard [row+1][column-2]); }
        if (finalBoard [row+2][column-2] != ' ')
        { sureValues.push_back(finalBoard [row+2][column-2]); }
     }
     if (column%3 == 0 && row%3 == 1)
     {
        if (finalBoard [row-1][column+1] != ' ')
        { sureValues.push_back(finalBoard [row-1][column+1]); }
        if (finalBoard [row-1][column+2] != ' ') 
        { sureValues.push_back (finalBoard [row-1][column+2]); }
        if (finalBoard [row+1][column+1] != ' ')
        { sureValues.push_back(finalBoard [row+1][column+1]); }
        if (finalBoard [row+1][column+2] != ' ')
        { sureValues.push_back(finalBoard [row+1][column+2]); } 
     }
     if (column%3 == 1 && row%3 == 1)
     {
        if (finalBoard [row-1][column-1] != ' ')
        { sureValues.push_back(finalBoard [row-1][column-1]); }
        if (finalBoard [row+1][column-1] != ' ') 
        { sureValues.push_back (finalBoard[row+1][column-1]); }
        if (finalBoard [row-1][column+1] != ' ')
        { sureValues.push_back(finalBoard [row-1][column+1]); }
        if (finalBoard [row+1][column+1] != ' ')
        { sureValues.push_back(finalBoard [row+1][column+1]); }
     }
     if (column%3 == 2 && row%3 == 1)
     {
        if (finalBoard [row-1][column-2] != ' ')
        { sureValues.push_back(finalBoard [row-1][column-2]); }
        if (finalBoard [row-1][column-1] != ' ') 
        { sureValues.push_back (finalBoard [row-1][column-1]); }
        if (finalBoard [row+1][column-2] != ' ')
        { sureValues.push_back(finalBoard [row+1][column-2]); }
        if (finalBoard [row+1][column-1] != ' ')
        { sureValues.push_back(finalBoard [row+1][column-1]); }
     }
     if (column%3 == 0 && row%3 == 2)
     {
        if (finalBoard [row-1][column+1] != ' ')
        { sureValues.push_back(finalBoard [row-1][column+1]); }
        if (finalBoard [row-2][column+1] != ' ') 
        { sureValues.push_back (finalBoard [row-2][column+1]); }
        if (finalBoard [row-1][column+2] != ' ')
        { sureValues.push_back(finalBoard [row-1][column+2]); }
        if (finalBoard [row-2][column+2] != ' ')
        { sureValues.push_back(finalBoard [row-2][column+2]); }
     }
     if (column%3 == 1 && row%3 == 2) 
     {
        if (finalBoard [row-1][column-1] != ' ')
        { sureValues.push_back(finalBoard [row-1][column-1]); }
        if (finalBoard [row-2][column-1] != ' ') 
        { sureValues.push_back (finalBoard [row-2][column-1]); }
        if (finalBoard [row-1][column+1] != ' ')
        { sureValues.push_back(finalBoard [row-1][column+1]); }
        if (finalBoard [row-2][column+1] != ' ')
        { sureValues.push_back(finalBoard [row-2][column+1]); }
     }
     if (column%3 == 2 && row%3 == 2)
     {
        if (finalBoard [row-2][column-2] != ' ')
        { sureValues.push_back(finalBoard [row-2][column-2]); }
        if (finalBoard [row-1][column-2] != ' ') 
        { sureValues.push_back (finalBoard [row-1][column-2]); }
        if (finalBoard [row-2][column-1] != ' ')
        { sureValues.push_back(finalBoard [row-2][column-1]); }
        if (finalBoard [row-1][column-1] != ' ')
        { sureValues.push_back(finalBoard [row-1][column-1]); }
     }
     return sureValues;
}
This article has been dead for over six months. Start a new discussion instead.