Still failing a function, not sure why...ideas on test cases to run?
Posted
by igor
on Stack Overflow
See other posts from Stack Overflow
or by igor
Published on 2010-04-06T16:52:16Z
Indexed on
2010/04/06
17:33 UTC
Read the original article
Hit count: 258
I've been trying to get this Sudoku game working, and I am still failing some of the individual functions. All together the game works, but when I run it through an "autograder", some test cases fail.. Currently I am stuck on the following function, placeValue, failing. I do have the output that I get vs. what the correct one should be, but am confused..what is something going on?
EDIT: I do not know what input/calls they make to the function.
What happens is that "invalid row" is outputted after every placeValue call, and I can't trace why..
Here is the output (mine + correct one) if it's at all helpful: http://pastebin.com/Wd3P3nDA
Here is placeValue, and following is getCoords that placeValue calls..
void placeValue(Square board[BOARD_SIZE][BOARD_SIZE])
{
int x,y,value;
if(getCoords(x,y))
{
cin>>value;
if(board[x][y].permanent)
{
cout<< endl << "That location cannot be changed";
}
else if(!(value>=1 && value<=9))
{
cout << "Invalid number"<< endl;
clearInput();
}
else if(validMove(board, x, y, value))
{
board[x][y].number=value;
}
}
}
bool getCoords(int & x, int & y)
{
char row;
y=0;
cin>>row>>y;
x = static_cast<int>(toupper(row));
if (isalpha(row) && (x >= 'A' && x <= 'I') && y >= 1 && y <= 9)
{
x = x - 'A'; // converts x from a letter to corresponding index in matrix
y = y - 1; // converts y to corresponding index in matrix
return (true);
}
else if (!(x >= 'A' && x <= 'I'))
{
cout<<"Invalid row"<<endl;
clearInput();
return false;
}
else
{
cout<<"Invalid column"<<endl;
clearInput();
return false;
}
}
© Stack Overflow or respective owner