Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program to score five card poker hands into one of the following categor

ID: 3623375 • Letter: W

Question

write a program to score five card poker hands into one of the following categories: nothing, one pair, two pairs, three of a kind , straight(in order with no gaps), flush(all the same suit, for example, all spades),full house(one pair and three of a kind), four of a kind, straight flush(both a straight and a flush). use two arrays, one to hold the value of the card and one to hold the suit. Include a loop that allows the user to continue to score more hand until the user says the program should end.

Explanation / Answer

please rate - thanks

#include <iostream>
#include <ctime>
#include<iomanip>
using namespace std;
void shuffle(int[],int[]);
void dealcards(int[],int[],int[],int[]);
bool checkflush(int[]);
bool checkstraight(int[]);
void same(int [],bool &,bool &,bool &,bool &,bool &);
int main()
{
int i,j,flushes,decks[52],deckn[52];
int hands[5],handn[5],scored,count;
bool flush,straight;
bool pair,pair2,three,four,nothing;
string suit[4]={"hearts","diamonds","spades","clubs"};
string card[13]={"ace","2","3","4","5","6","7","8","9","10","jack","queen","king"};
int deal;
char yesno='Y';
srand(time(0));
do
{scored=0;
shuffle(decks,deckn);
   cout<<"deck-after shuffled: ";
       for(j=0;j<52;j++)
           cout<<card[deckn[j]]<<" "<<suit[decks[j]]<<endl;
       cout<<endl;
dealcards(hands,handn,decks,deckn);
cout<<"Hand: ";
       for(j=0;j<5;j++)
          cout<<card[handn[j]]<<" "<<suit[hands[j]]<<endl;
    cout<<endl;
flush=checkflush(hands);
straight=checkstraight(handn);
same(handn,nothing,pair,pair2,three,four);
cout<<" scoring: ";
if(straight&&flush)
     cout<<"straight flush ";
else if(pair&&three)
      cout<<"full house ";  
else if(straight)
     cout<<"straight ";
else if(flush)
     cout<<"flush ";   
else if(four)
     cout<<"four of a kind ";  
else if(three)
     cout<<"Three of a kind ";
else if(pair2)
     cout<<"2 pair ";             
else if(pair)
    cout<<"one pair ";
else
    cout<<"nothing ";     
    
cout<<" Play again (Y/N)?";
cin>>yesno;
}while(toupper(yesno)=='Y');
system("pause");
return 0;
}
bool checkstraight(int handn[])
{int i,j,t;
for(i=0;i<4;i++)
    for(j=i+1;j<5;j++)
        if(handn[i]>handn[j])
            {t=handn[i];
            handn[i]=handn[j];
            handn[j]=t;
            }
for(i=1;i<5;i++)
    if(handn[i]!=handn[i-1]+1)
          return false;
return true;
}
void same(int handn[],bool &nothing,bool &pair,bool &pair2,bool &three,bool &four)
{bool used[13]={false};
nothing=false;
pair=false;
pair2=false;
three=false;
four=false;
int b[13]={0};
int i,j;
for( i = 0; i < 5; i++)
{if(!used[handn[i]])
   {int count = 1;
   for(int j = i+1; j < 5; j++)
      {
      if(handn[j] == handn[i])
           {
            count++;

            }
         }
     used[handn[i]]=true;
     b[handn[i]]=count;
    }

}


cout<<endl;
for(i=0;i<13;i++)
   if(b[i]==4)
      {four=true;
       return;
       }
    else if(b[i]==3)
       {three=true;
        for(j=0;j<13;j++)
             if(b[j]==2)
                 pair=true;
         return;       
       }
     else if(b[i]==2)
         {pair=true;
         for(j=0;j<13;j++)
             if(b[j]==3)
                 three=true;
          for(j=i+1;j<13;j++)
             if(b[j]==2)
                {pair2=true;
                return;
                }
          return;
          }
nothing=true;
return;   
}
void dealcards(int hands[],int handn[],int decks[],int deckn[])
{int i,j,cards=0;
for(i=0;i<5;i++)
       {hands[i]=decks[cards];
        handn[i]=deckn[cards];       
        cards++;
        }
return;
}
     
bool checkflush(int hands[])
{int j,count=0,type,handcount;
type=hands[0];
handcount=1;
for(j=1;j<5;j++)
if(hands[j]==type)
       handcount++;
if(handcount==5)
        return true;
else
        return false;
}  
     
void shuffle(int decks[],int deckn[])   
{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;
         }

return;
}