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

Recommended Answers

All 5 Replies

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 ;)

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.

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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.