Code:
#include <iostream>
using namespace std;
struct card
{int value; char suit;};
card c2={2,'c'}; card d2={2,'d'}; card s2={2,'s'}; card h2={2,'h'};
card c3={3,'c'}; card d3={3,'d'}; card s3={3,'s'}; card h3={3,'h'};
card c4={4,'c'}; card d4={4,'d'}; card s4={4,'s'}; card h4={4,'h'};
card c5={5,'c'}; card d5={5,'d'}; card s5={5,'s'}; card h5={5,'h'};
card c6={6,'c'}; card d6={6,'d'}; card s6={6,'s'}; card h6={6,'h'};
card c7={7,'c'}; card d7={7,'d'}; card s7={7,'s'}; card h7={7,'h'};
card c8={8,'c'}; card d8={8,'d'}; card s8={8,'s'}; card h8={8,'h'};
card c9={9,'c'}; card d9={9,'d'}; card s9={9,'s'}; card h9={9,'h'};
card cT={10,'c'}; card dT={10,'d'}; card sT={10,'s'}; card hT={10,'h'};
card cJ={11,'c'}; card dJ={11,'d'}; card sJ={11,'s'}; card hJ={11,'h'};
card cQ={12,'c'}; card dQ={12,'d'}; card sQ={12,'s'}; card hQ={12,'h'};
card cK={13,'c'}; card dK={13,'d'}; card sK={13,'s'}; card hK={13,'h'};
card cA={14,'c'}; card dA={14,'d'}; card sA={14,'s'}; card hA={14,'h'};
int checksuited(card first, card second, card third, card fourth, card fifth);
int checkforaceishigh(card first, card second, card third, card fourth, card fifth);
int checkconsecutive(card first, card second, card third, card fourth, card fifth);
int checkfor4k(card first, card second, card third, card fourth, card fifth);
int firstsort(int suited,int consecutive,int aceishigh);
int prelimcheck(card first,card second,card third,card fourth,card fifth);
int suited,consecutive,aceishigh,handvalue;
int prelimcheck2(card first, card second, card third, card fourth, card fifth);
int checkfor3k(card first, card second, card third, card fourth, card fifth);
int checkforpair45(card fourth, card fifth);
int checkforpair12(card first, card second);
int secondsort(int threeofakind, int pair45, int pair12);
int threeofakind, firstpairno3, pair45, pair12;
int prelimcheck4(card first, card second, card third, card fourth, card fifth);
int checkforpairs123(card first, card second, card third);
int checkforpairs345(card third, card fourth, card fifth);
int thirdsort(int earlypairno3, int latepairno3);
int earlypairno3,latepairno3;
int result(int handvalue);
card first,second,third,fourth,fifth;
int main()
{
first=dA;second=dK,third=sK;fourth=c3;fifth=d2;
cin.get();
handvalue=prelimcheck(first,second,third,fourth,fifth);//Checking for Royal flush,
if (handvalue!=0) //Straight Flush or Straight
{result(handvalue);}
handvalue=checkfor4k(first, second, third, fourth, fifth);//Checking for 4 of a kind
if (handvalue!=0)
{result(handvalue);}
handvalue=prelimcheck2(first, second, third, fourth, fifth);//Checking for Full House
if (handvalue!=0) //or 3 of a kind
{result(handvalue);}
handvalue=prelimcheck4(first, second, third, fourth, fifth);
result(handvalue);
cout<<"You should not see this line on screen";
return 0;
}
/* Below this line, is where we check for Royal Flush, Flush or Straight*/
int prelimcheck(card first,card second,card third,card fourth,card fifth)
{
suited=checksuited(first, second, third, fourth, fifth);
aceishigh=checkforaceishigh(first, second, third, fourth,fifth);
consecutive=checkconsecutive(first, second, third, fourth, fifth);
if (aceishigh==0)
{consecutive=1;}
handvalue=firstsort(suited,consecutive,aceishigh);
return handvalue;
}
int checksuited(card first, card second, card third, card fourth, card fifth)
{
if (first.suit==second.suit&&second.suit==third.suit&&third.suit==fourth.suit&&fourth.suit==fifth.suit)
{suited=1;}
else
{suited=0;}
return suited;
}
int checkforaceishigh(card first, card second, card third, card fourth, card fifth)
{
if (first.value==14&&second.value==5&&third.value==4&&fourth.value==3&&fifth.value==2)
{aceishigh=0;}
else
{aceishigh=1;}
return aceishigh;
}
int checkconsecutive(card first, card second, card third, card fourth, card fifth)
{
if (first.value==(second.value+1)&&second.value==(third.value+1)&&third.value==(fourth.value+1)&&fourth.value==(fifth.value+1))
{consecutive=1;}
else
{consecutive=0;}
return consecutive;
}
int firstsort(int suited,int consecutive,int aceishigh)
{
if (suited==1&&consecutive==1&&aceishigh==1)
{ handvalue=1;}
if (suited==1&&consecutive==1&&aceishigh==0)
{ handvalue=2;}
if (suited==1&&consecutive==0)
{ handvalue=5;}
if (suited==0&&consecutive==1)
{ handvalue=6;}
else
{ handvalue=0;}
return handvalue;
}
/*Above this line, is where we check for Royal Flush, Flush or Straight*/
/*Below this line, is where we check for Four of a Kind*/
int checkfor4k(card first, card second, card third, card fourth, card fifth)
{
if((first.value==second.value&&second.value==third.value&&third.value==fourth.value)||(second.value==third.value&&third.value==fourth.value&&fourth.value==fifth.value))
{handvalue=3;}
else
{handvalue=0;}
return handvalue;
}
/*Above this line, is where we check for Four of a Kind*/
/*Below this line, is where we check for Three of a kind or Full House*/
int prelimcheck2(card first, card second, card third, card fourth, card fifth)
{
threeofakind=checkfor3k(first, second, third, fourth, fifth);
pair45=0;pair12=0; //ensuring they are 0 before we start
if (threeofakind==123)
{pair45=checkforpair45(fourth, fifth);}
if (threeofakind==345)
{pair12=checkforpair12(first, second);}
handvalue=secondsort(threeofakind,pair45,pair12);
return handvalue;
}
int checkfor3k(card first, card second, card third, card fourth, card fifth)
{
if(first.value==second.value&&second.value==third.value)
{threeofakind=123;}
if(second.value==third.value&&third.value==fourth.value)
{threeofakind=234;}
if(third.value==fourth.value&&fourth.value==fifth.value)
{threeofakind=345;}
else
{threeofakind=0;}
return threeofakind;
}
int checkforpair45(card fourth, card fifth)/*this is only called, if 1,2,3 are 3 of a kind*/
{
if(fourth.value==fifth.value)
{pair45=45;}
else
{pair45=0;}
return pair45;
}
int checkforpair12(card first, card second)/*this is only called, if 3,4,5 are 3 of a kind*/
{
if(first.value==second.value)
{pair12=12;}
else
{pair12=0;}
return pair12;
}
int secondsort(int threeofakind, int pair45, int pair12)
{
if (threeofakind==123)
{
if (pair45==45)
{handvalue=4;}
if (pair45==0)
{handvalue=7;}
}
if (threeofakind==345)
{
if (pair12==12)
{handvalue=4;}
if (pair12==0)
{handvalue=7;}
}
if (threeofakind==234)
{handvalue=7;}
else
{handvalue=0;}
return handvalue;
}
/*Above this line, is where we check for Three of a kind or Full House*/
/*Below this line, we check for 2 pair, Jacks or Better or Bust*/
int prelimcheck4(card first, card second, card third, card fourth, card fifth)
{
earlypairno3=checkforpairs123(first, second, third);
latepairno3=checkforpairs345(third, fourth, fifth);
handvalue=thirdsort(earlypairno3, latepairno3);
return handvalue;
}
int checkforpairs123(card first, card second, card third)
{
if((first.value==second.value)||(second.value=third.value))
{if (second.value>10)
{earlypairno3=222;}
else
{earlypairno3=2;}
}
else
{earlypairno3=0;}
return earlypairno3;
}
int checkforpairs345(card third, card fourth, card fifth)
{
if((third.value==fourth.value)||(fourth.value==fifth.value))
{if (fourth.value>10)
{latepairno3=444;}
else
{latepairno3=4;}
}
else
{latepairno3=0;}
return latepairno3;
}
int thirdsort(int earlypairno3, int latepairno3)
{
if ((earlypairno3>0)&&(latepairno3>0))
{handvalue=8;}
else
{if ((earlypairno3>100)||(latepairno3>100))
{handvalue=9;}
else
{handvalue=0;}}
return handvalue;
}
/*Above this line we check for 2 pair, Jacks or better or Bust*/
/*Below this line, we output the result*/
int result(int handvalue)
{ switch(handvalue)
{ case 1:
cout<<"Royal Straight Flush";
break;
case 2:
cout<<"Straight Flush";
break;
case 3:
cout<<"Four of a Kind";
break;
case 4:
cout<<"Full House";
break;
case 5:
cout<<"Straight";
break;
case 6:
cout<<"Flush";
break;
case 7:
cout<<"Three of a Kind";
break;
case 8:
cout<<"Two Pair";
break;
case 9:
cout<<"Jacks or Better";
break;
case 0:
cout<<"Bust";
break;
default:
cout<<"Error";
break;
}
main();
}