Hi,
My program logic is working great for five card poker game and hand contains a pair and iterated the loop to find how many times program ran until pair were dealt.but, it will not display the cards it was dealt more than 10 times.
I am sure program logic is correct 100%.But, when i change the program to four of a kind and iterated in do... while loop to find how many times were dealt to determine four of a kind, my output shows no.of times were dealt but not displaying the cards along with suits. pls help me out to display my cards in output!!!
Note: I just highlighted the those two lines in box.
#include <iostream>
#include <ctime> //Prototype for time
#include <iomanip>
#include <string.h>
using namespace std;
void shuffle(int[],int[]);
void dealcards(int[],int[],int[],int[],int&,int);
bool duplicates(int[]);
long num_of_times_dealt=0;
int main()
{
const int HANDSIZE=5;
int i,j,decks[52],deckn[52];
int count[13]={0};
int suits[HANDSIZE],ranks[HANDSIZE],cards=0,low;
string suit[4]={"hearts","diamonds","spades","clubs"};
string card[13]={"ace","2","3","4","5","6","7","8","9","10","jack","queen","king"};
do
{
srand(time(0));
shuffle(decks,deckn);
dealcards(suits,ranks,decks,deckn,cards,HANDSIZE);
num_of_times_dealt++;
}while(!duplicates(ranks));
cout<<num_of_times_dealt<<" no. of times dealt displayed before printing cards "<<endl;
1 2
|
for(j=0;j<HANDSIZE;j++)
cout<<card[ranks[j]]<<"\t"<<suit[suits[j]]<<endl;
|
cout<<"The hand contains four of a kind. Number of times dealt: ";
cout<<num_of_times_dealt;
cout<<endl;
system("pause");
//return 0;
}
bool duplicates(int nums[]) //duplicates is a function to determine whether hand contains a four of a kind
{
int i,j;
int count[13]={0};
for(i=0;i<5;i++)
count[nums[i]]++;
for(i=0;i<13;i++)
if(count[i]==4)
return true;
return false;
} //end duplicates function
void dealcards(int hands[],int handn[],int decks[],int deckn[],int & cards,int HANDSIZE)
{
int i,j,t;
int rank[]={13,2,3,4,5,6,7,8,9,10,11,12};
for(i=0;i<5;i++)
{
hands[i]=decks[cards];
handn[i]=deckn[cards];
cards++;
} //end for loop
for(i=0;i<4;i++)
for(j=i+1;j<HANDSIZE;j++)
if(rank[handn[i]]>rank[handn[j]])
{
t=hands[i];
hands[i]=hands[j];
hands[j]=t;
t=handn[i];
handn[i]=handn[j];
handn[j]=t;
}// end if statement
return;
} //end dealcards function
void shuffle(int decks[],int deckn[]) //Shuffle cards in deck
{
bool cards[4][13];
int i,j,num,type;
for(i=0;i<4;i++)
for(j=0;j<13;j++)
cards[i][j]=false;
for(j=0;j<52;j++)
{
do
{
num=rand()%13;
type=rand()%4;
}while(cards[type][num]);
decks[j]=type;
deckn[j]=num;
cards[type][num]=true;
} // end for loop
return;
} // end function shuffle
regards,
preethi.