Reputation: 177
Hello I'm 17 and trying to learn how to code. I am having trouble debugging this section of code and would appreciate some help.
bool checkifwin(char grid[3][3], char player)
{
if (checkverticle(char grid[3][3], char player)
|| checkhorizontal(char grid[3][3], char player)
|| checkdiagonal( grid[3][3], player)
return true;
else
return false;
};
It says expected primary-expression before char.
Upvotes: 1
Views: 300
Reputation: 29266
checkverticle() is a call to a function not a declaration so you don't need the "char"s.
bool checkifwin(char grid[3][3], char player)
{
if ( checkverticle(grid, player) ||
checkhorizontal(grid, player) ||
checkdiagonal( grid, player) return true;
else return false;
};
Just some coding advice. In my opinion:
bool func()
{
if (expr)
return true;
else
return false;
}
Is not great style. I'd suggest refactoring it to:
bool func()
{
bool result = false; // This just makes it clear the expected default.
// You could even go as far as
// bool result = expr or event return expr; - although I suggest sticking with a
// variable in case you need to debug.
result = expr; // e.g. result = checkVert() || checkHoriz() || checkDiag();
return result;
}
Upvotes: 4
Reputation: 34655
There is no need to give type name while calling a function.
if (checkverticle(char grid[3][3], char player) // Remove char here and in other cases
Regarding the error further you get -
checkverticle( grid[3][3] ... )
Here grid[3][3]
gives you the character at that index. What you really want to pass is grid
itself as others suggested. And ofcourse, be wary of the valid array indexes.
Upvotes: 2
Reputation: 125747
You're trying to pass type declarations as parameters. Try this instead:
bool checkifwin(char grid[3][3], char player)
{
return checkverticle(grid], player) ||
checkhorizontal(grid, player) ||
checkdiagonal(grid, player;
};
Upvotes: 1