im trying to print a certain message according to the return value using 2 different functions. when call the function inside the other is says things are not declared
int isMatch(int x1, int y1, int x2, int y2)
{
if(deck[x1][y1] == deck[x2][y2])
{
return 2;
}
else if(deck[x1][y1][0] == deck[x2][y2][0])
{
return 1;
}
else if(deck[x1][y1][1] == deck[x2][y2][1])
{
return 1;
}
return 0;
}
void printMatch()
{
int attempt;
isMatch(x1, y1, x2, y2);
if(isMatch() == 2)
{
cout << "You have a match!";
attempt++;
}
}
when i try it like this, it still doesnt work
int isMatch(int x1, int y1, int x2, int y2)
{
if(deck[x1][y1] == deck[x2][y2])
{
return 2;
}
else if(deck[x1][y1][0] == deck[x2][y2][0])
{
return 1;
}
else if(deck[x1][y1][1] == deck[x2][y2][1])
{
return 1;
}
return 0;
}
void printMatch()
{
int attempt;
int isMatch(int x1, int y1, int x2, int y2);
if(isMatch() == 2)
{
cout << "You have a match!";
attempt++;
}
}
!!!!!!!!!! UPDATE !!!!!!!!!!!!!!!!!
int isMatch(int x1, int y1, int x2, int y2)
{
if(deck[x1][y1] == deck[x2][y2]) /// Checks entire element (_,_)
{
return 2;
}
else if(deck[x1][y1][0] == deck[x2][y2][0]) /// Checks first element (_, )
{
return 1;
}
else if(deck[x1][y1][1] == deck[x2][y2][1]) /// Checks second element ( ,_)
{
return 1;
}
return 0;
}
void printMatch()
{
int attempt = 0; /// increments the users attempts
int score = 0; /// adds total score
int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
int match = isMatch(x1, y1, x2, y2);
if (match == 2)
{
attempt++;
score = score + 2;
cout << "\nYou have a match!"
<< "\nTotal score is: " << score
<< "\nTotal no. of attempts: " << attempt << endl << endl;
}
else if (match == 1)
{
attempt++;
score = score + 1;
cout << "\nYou have a match!"
<< "\nTotal score is: " << score
<< "\nTotal no. of attempts: " << attempt << endl << endl;
}
}