I am working on a class member function and am getting a couple of error messages that I don't understand.
I am getting the following error messages:
error 1 I think is because I'm performing a sqrt function which must be a double and putting it in an integer variable - converting to 'int' from 'double'
error2: non -1 value in assignment
The code below is supposed to run the blank function on vector p and find which location the blank spot is in. If the blank spot is in an "acceptable" position then the operation is performed. For example, if I had a vector of size 16 (user chooses side length and a vector of side length squared is created), I am filling the vector with the numbers from 1 through 15 and then leaving a "blank". for the example below, if the blank isn't located in the bottom row (vector is displayed as 4 rows and 4 columns) then the blank is swapped with the contents of the vector address directly above it.
Please help me.
Code:
bool Puzzle::slide_up(const Puzzle& p) const {
int location=blank(p);
int d=Puzzle::p.size();
int rows=sqrt(d);
if(location<d-rows){
int temp;
temp=location;
location=location+rows;
location+rows=temp;
return true;
}
else
return false;
}