My program deals out 7 cards. And then determines what is in the hand. A pair, two pair, three pair, four of a kind. However its not finding any of those right and im not sure why.
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
#include "DeckOfCards.h"
DeckOfCards::DeckOfCards()
{
int i = 1;
for ( int row = 0; row <= 3; row++ )
{
for ( int column = 0; column <= 12; column++ )
{
deck[ row ][ column ] = i;
i = i + 1;
}
}
srand( (unsigned int) time( 0 ) );
}
void DeckOfCards::shuffle()
{
int row;
int column;
int row1;
int column1;
int swap;
for (row=0; row<=3; row++)
{
for (column=0; column<=12; column++)
{
row1= rand()%4;
column1=rand()%13;
swap=deck[row][column];
deck[row][column]=deck[row1][column1];
deck[row1][column1]=swap;
}
}
}
void DeckOfCards::deal()
{
int hand[7];
int index=0;
int pairs=0;
int kind=0;
bool pair=false;
static const char *suit[ 4 ] =
{ "Hearts", "Diamonds", "Clubs", "Spades" };
static const char *face[ 13 ] =
{ "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
for (int card = 1; card <= 7; card++)
{
for (int row = 0; row <= 3; row++)
{
for (int column = 0; column <= 12; column++ )
{
if (deck[ row ][ column ] == card)
{
hand[index]=(row*13)+column;
index++;
}
}
}
}
for (int i=0; i<7; i++)
cout << "\n" << face[hand[i]%13]<< " of " << suit[hand[i]/13];
cout << "\n";
{
for (int x=0; x<4; x++)
for (int y=x+1; y<5; y++)
if((hand[x]==(hand[y]-1))||(hand[x]==(hand[y]+1)))
if((x/13)==(y/13))
{
cout << "\nThe hand has a pair! ";
pair=true;
}
if(!pair)
cout << "\nNo pair in hand. ";
}
{
for(int x=0; x<4; x++)
for(int y=x+1; y<5; y++)
if((hand[x]==(hand[y]-1))||(hand[x]==(hand[y]+1)))
if((x/13)==(y/13))
{
cout << "\nThe hand has a two pair! ";
pairs++;
}
}
{
for (int x=0; x<3;x++)
{
kind=0;
for (int y=x+1;y<5;y++)
if ((hand[x]/1)==(hand[y]/13))
kind++;
if (kind>=2)
{
cout << "\nThere is a three of a kind in hand!\n ";
}
}
}
{
{
for (int x=0; x<2;x++)
{
kind=0;
for (int y=x+1;y<5;y++)
if ((hand[x]/13)==(hand[y]/13))
kind++;
if (kind>=3)
{
cout << "\nThere is a four of a kind! ";
}
}
}
}
}
int main()
{
DeckOfCards deckOfCards;
deckOfCards.shuffle();
deckOfCards.deal();
return 0;
}