First, you need a structuce:
Code:
struct Card
{
int number, value;
bool found;
};
And initialization:
Code:
Card deck[20];
for(int i = 0; i < 20; i++)
{
deck[i].found = 0;
deck[i].number = i;
if(i < 10)
deck[i].value = i+1;
else
deck[i].value = i+1-10;
}
Perhaps a shuffle:
Code:
Card temp;
int swap;
for(int i = 0; i < 123; i++)
{
temp = deck[rand()%20];
for(;;)
{
i = rand()%20;
if(i != swap.number)
break;
}
deck[temp.number] = deck[swap];
deck[swap] = temp;
}
(write in a hurry - beware of errors!)
Now just flag the cards that have been found and compare the values to find a pair.
Code:
get input to a and b
if((deck[a].value == deck[b].value) && (deck[a].found = 0))
{
Match found!
deck[a].found = deck[b].found = 1;
}
And for a final check
Code:
int i;
for(i = 0; i < 20; i++)
if(deck[i].found == 0)
break;
if(i == 19)
all cards found