I need a little help with this one...
DOC.cpp
void DeckOfCards::findPair(const char *pairCheck[])
{
const char *pairEval[5] = {0};
int fourOfKind = 0;
int fourCount = 1;
for(int index = 0; index < 5; index++) // Make a copy of pairCheck for evaluation
{
pairEval[index] = pairCheck[index]; // Copying pairCheck elements to pairEval
}
cout << "\n\n";
for(int index = 0; index < 4; index++)
{
for(int index2 = (index + 1); index2 < 5; index2++) // Since index2 needs to be one location
// ahead of index at all times, index2 = index+1
{
if(strcmp(pairCheck[index2], pairEval[index]) == 0) // if the indexes are a match, increase match counter.
{
fourCount++;
}
}
}
for(int x = 0; x < 4; x++)
{
if(strcmp(pairEval[x], pairEval[x + 1]) == 0)
fourOfKind++;
}
if(fourOfKind >= 4)
setCounter(fourOfKind); // pass fourOfKind by value to the member variable
else
{
fourOfKind = 0;
setCounter(fourOfKind);
}
}
main.cpp
int main()
{
long int timesRan = 0; // Amt of times the cards were dealt until a 4 of a kind was discovered.
int fourFound = 0; // hopefuly find a four of a kind of stop the loop
do
{
++timesRan; // Count the amount of times the loop is ran
DeckOfCards deckOfCards; // create DeckOfCards object in loop for continuous play
deckOfCards.shuffle(); // shuffle the cards in the deck
deckOfCards.deal(); // deal the cards
fourFound = deckOfCards.getCounter(); // Retrieve the four of a kind counter using getCounter() (member variable)
}while(fourFound < 4); // while fourFound is not > 4, loop
cout << "A four of a kind was found after " << timesRan << " hands." << endl; // Print the amt of loops ran before 4 of a kind was found
cin.get();
return 0; // indicates successful termination
} // end main

New Topic/Question
Reply



MultiQuote




|