Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

help with memory game (pairs)

hi! i made this code that should run like the classic pairs game. the problem is, it isn't doing what it's supposed to do. when the user inputs the same coordinates consecutively it should display "invalid input" the ask for another input, instead, it leaves the "asterisk/card" open. help me please? i need to figure it out in 5 hours.. i'm a newbie. thanks

[code=c]
#include
#include
#include
#include "generate.h"

int main(void){
int a, b, c, d;
int i, j, moves;
char board[6][6];
char incboard[6][6]={"******","******","******","******","******","******"};
char opencheck[6][6]={"000000", "000000", "000000", "000000", "000000", "000000",};
moves=0;
make_matrix(board);//connects the generated matrix/answer key to the program
for(i=0;i<6;i++)//prints the matrix
{
for(j=0;j<6;j++)
{
printf(" %c",incboard[i][j]);
}
printf("
");
}




for (i=0; i<6; i++){
for (j=0;j<6;j++)
{
if (incboard[i][j]!='*')
{
printf("
Congratulations! You were able to match all the pairs in %d moves", moves);
}
//checks if matrix and the answer key are the same
else
{
//lets the user enter the 1st set of coordinates
printf("
Enter coordinates in the form of row,column:");
getch();
scanf("%d,%d", &a, &b);

//locates the coordinates given by the user if the input is valid
if (a>0 && a<=6 && b>0 && b<=6 && opencheck[a][b]!='1')
{
a--;
b--;
system("cls");
processBoard(a, b, board, incboard, opencheck);
//lets the user enter the 2nd set of coordinates
printf("
Enter another set of coordinates in the form of row,column:");
getch();
scanf("%d,%d", &c, &d);

//locates the coordinates given by the user
if ((++a!=c && ++b!=d)||c>0 && c<=6 && d>0 && d<=6 && opencheck[c][d]!='1')
{
system ("cls");
c--;
d--;
moves++;//counts the number of moves the user made
processBoard(c, d, board, incboard, opencheck);
checkmatch(a, b, c, d, incboard, opencheck);
}


//checks if the 2nd set of coordinates given by the user is valid
else if((isdigit(c))==0||(isdigit(d))==0||c<=0||c>6||d<=0||d>6){
printf("Invalid input
");
do{
printf("
Enter another set of coordinates in the form of row,column:");
getch();
scanf("%d,%d", &c, &d);
}while((isdigit(c))==0||(isdigit(d))==0||c<=0||c>6||d<=0||d>6);
}
else
{
printf("Invalid input
");
}

}

//checks if the 1st set of coordinates given by the user is valid
else if((isdigit(a))==0||(isdigit(b))==0||a<=0||a>6||b<=0||b>6)
{
printf("Invalid input
");
}
}
}
}


}




//processes the board and locates the position using coordinates given by the user
int processBoard(int a, int b, char board[6][6], char incboard[6][6], char opencheck[6][6]){
int i,j;
incboard[a][b]=board[a][b];
opencheck[a][b]='1';
//displays the character value in the matrix of the given coordinate
for (i=0; i<6; i++)
{
for(j=0; j<6; j++)
{
printf(" %c", incboard[i][j]);
}
printf("
");
}
}


//checks if the elements of the coordinates given by the user are the same
int checkmatch(int a, int b, int c, int d, char incboard[6][6], char opencheck[6][6]){
int i, j;

if (incboard[a][b]!= incboard[c][d]){
sleep(3);
system("cls");
opencheck[a][b]='0';
opencheck[c][d]='0';
incboard[c][d]='*';
incboard[a][b]='*';

//prints the matrix
for(i=0;i<6;i++){
for(j=0;j<6;j++){
printf(" %c",incboard[i][j]);
}
printf("
");
}
}

else {
opencheck[a][b]='1';
opencheck[c][d]='1';
}

}

[code]

Sign In or Register to comment.