Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cstring>
#define draw 5;
using namespace std;
void f_shuffle (int _deck [] [13]);
void f_deal (int _hand [] [13], const int _deck [] [13]);
void f_c_hand( const int _hand [] [13], const char *_face[], const char *_suit[] );
void f_wins (const int _hand [] [13], const char *_face[], const char *_suit[]);
void f_pair (char *face_card[]);
main()
{ const char *suit [4]={
"Hearts", "Diamonds", "Clubs", "Spades",};
const char *face [13]={
"Ace", "Deuce", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King",};
int deck [4] [13]={0};
int hand [4] [13]={0};
srand (time(0));
f_shuffle (deck);
f_deal (hand, deck);
f_c_hand(hand, face, suit);
f_wins (hand, face, suit);
return(0);
}
void f_shuffle (int _deck [] [13])
{ int row, column;
for ( int card = 1; card <=52; card++)
{ do
{ row=rand() %4;
column=rand() %13;
}while (_deck [row] [column] !=0);
_deck [row] [column] = card;
}
}
void f_deal (int _hand[][13], const int _deck [][13])
{
for (int card=1; card<=draw; card++)
{ for (int row=0; row<=3; row++)
{ for (int column=0; column <=12; column++)
{ if (_deck [row] [column] == card)
{ _hand [row] [column] = 1;
}
}
}
}
}
void f_c_hand( const int _hand [] [13], const char *_face[], const char *_suit[] )
{ cout<<"Your Hand: "<<endl<<endl;
for (int row=0; row<=3; row++)
{ for (int column=0; column <=12; column++)
{ if (_hand [row] [column] == 1)
{ cout<<setw(5)<<setiosflags(ios::right)
<<_face[column]
<<" of "<<_suit[row]<<endl;
}
}
}
}
void f_wins (const int _hand [] [13], const char *_face[], const char *_suit[])
{ int counter=0;
char *face_card [5]={"12345", "12345", "12345", "12345", "12345"};
char *suit_card [5]={"12345678", "12345678", "12345678", "12345678", "12345678"};
for (int column=0; column<13; column++)
{ for (int row=0; row<4; row++)
{ if (_hand [row] [column] ==1)
{ counter++;
strcpy(face_card[counter], _face[column]);
strcpy(suit_card[counter], _suit[row]);
}
}
}f_pair(face_card);
}
void f_pair (char *face_card[])
{
for (int i=0; i<draw; i++)
{ for (int j=i+1; j<draw-1; ++j)
{ if (strcmp(face_card[i], face_card[j])==0)
{ cout<<"you have a match"<<endl;
cout<<face_card[i]<<endl<<endl;
}
}
}
}