### Matching game help!!

I encountered the problem for the numbers to remain if they are a pair until the game end. I have no idea on how to do it so please anyone help!?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156`` `````` #include #include #include void func(); void main() { func(); } void func() { int num[4][4]={1,2,3,4,1,2,3,4,5,6,7,8,5,6,7,8}; int arrayA[8],arrayB[8],arrayC[8],arrayD[8]; int round,row,col; system("cls"); printf("Welcome Player2 !"); printf("\n\n"); printf("**************************************************************************\n"); printf("GUESS THE TWO LOCATION OF A NUMBER GAME\n"); printf("**************************************************************************\n"); for(row=0;row<4;row++) { for(col=0;col<4;col++) { printf("0\t"); } printf("\n"); } printf("\n\n"); for(round=0; round<8;round++) { do { do { flushall(); printf("Which array would you like to open:: "); scanf("%d%d",&arrayA[round],&arrayB[round]); if(arrayA[round]>4 || arrayB[round]>4 || arrayA[round]<1 || arrayB[round]<1) { printf("\nInvalid position please retry\n\n"); } } while(arrayA[round]>4 || arrayB[round]>4 || arrayA[round]<1 || arrayB[round]<1); system("cls"); for(row=0;row<4;row++) { for(col=0;col<4;col++) { if(row == arrayA[round]-1 && col == arrayB[round]-1) { printf("%d\t",num[arrayA[round]-1][arrayB[round]]-1); } else { printf("%d\t",0); } } printf("\n"); } do { printf("Which 2nd array would you like to guess as a match: "); scanf("%d%d",&arrayC[round],&arrayD[round]); if(arrayC[round]>4 || arrayD[round]>4 || arrayC[round]<1 || arrayD[round]<1) { printf("Invalid position please retry\n"); } else if(arrayA[round]==arrayC[round] && arrayB[round]==arrayD[round]) { printf("You already guess this postion please reselect second position!!"); } flushall(); printf("\n\n"); } while(arrayC[round]>4 || arrayD[round]>4 || arrayC[round]<1 || arrayD[round]<1 || arrayA[round]==arrayC[round] && arrayB[round]==arrayD[round]); for(row=0;row<4;row++) { for(col=0;col<4;col++) { if(row == arrayA[round]-1 && col == arrayB[round]-1) { printf("%d\t",num[arrayA[round]-1][arrayB[round]-1]); } else if(row == arrayC[round]-1 && col == arrayD[round]-1) { printf("%d\t",num[arrayC[round]-1][arrayD[round]-1]); } else { printf("0\t"); } } printf("\n"); } if(num[arrayA[round]-1][arrayB[round]-1] != num[arrayC[round]-1][arrayD[round]-1]) { Sleep(500); system("cls"); for(row=0;row<4;row++) { for(col=0;col<4;col++) { printf("0\t"); } printf("\n"); } } } while(num[arrayA[round]-1][arrayB[round]-1] != num[arrayC[round]-1][arrayD[round]-1]); } }``````
You have the 2D num array.

 ``1234567`` `````` int num[4][4]= { {1,2,3,4}, {1,2,3,4}, {5,6,7,8}, {5,6,7,8} };``````

Consider also keeping another 2D array that indicates when values should be shown.

` bool showNum[4][4] = { false }; // initialize `

Then, when it's time to display the 'board' you use showNum[i][j] to determine if you should show the user num[i][j] or 0.

 ``1234567891011121314`` ``````void showBoard(const int num[][4], const bool show[][4]) { for ( unsigned y=0; y<4; ++y ) { for ( unsigned x=0; x<4; ++x ) { if ( show[y][x] ) printf("%d\t", num[y][x]) ; else printf("0\t") ; } printf("\n") ; } }``````

Topic archived. No new replies allowed.