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

C++ write a function that obtains a 5 card poker hand from the user. Use two arr

ID: 3715727 • Letter: C

Question

C++ write a function that obtains a 5 card poker hand from the user. Use two arrays — one for the card number (2-9, k/q/j/a) and the other array for suit (s/d/h/c). Sort the user entered hand into the following categories: pair, two pair, straight, three of a kind, four of a kind, flush, straight flush, full House.
I’ve asked this question before but only got an answer that takes in input for number cards. I need to incorporate race cards and suit of the card in order to be able to use flush C++ write a function that obtains a 5 card poker hand from the user. Use two arrays — one for the card number (2-9, k/q/j/a) and the other array for suit (s/d/h/c). C++ write a function that obtains a 5 card poker hand from the user. Use two arrays — one for the card number (2-9, k/q/j/a) and the other array for suit (s/d/h/c). C++ write a function that obtains a 5 card poker hand from the user. Use two arrays — one for the card number (2-9, k/q/j/a) and the other array for suit (s/d/h/c). C++ write a function that obtains a 5 card poker hand from the user. Use two arrays — one for the card number (2-9, k/q/j/a) and the other array for suit (s/d/h/c). C++ write a function that obtains a 5 card poker hand from the user. Use two arrays — one for the card number (2-9, k/q/j/a) and the other array for suit (s/d/h/c). Sort the user entered hand into the following categories: pair, two pair, straight, three of a kind, four of a kind, flush, straight flush, full House.
I’ve asked this question before but only got an answer that takes in input for number cards. I need to incorporate race cards and suit of the card in order to be able to use flush

Explanation / Answer

//remember there will be no output in case no categorie fit in with the given data

//and also you have given only permission of 2-9 so i have omitted 10 from cards so 9 j q k a will form a stright flush

//and remaing will be affected accordingly

#include<iostream>

using namespace std;

int main()

{

char card[5],suit[5];

int count[5]={0};

cout<<"enter card and then its suit ";

for(int i=0;i<5;i++)

{

cin>>card[i]>>suit[i];

}

for(int i=0;i<5;i++)

{

for(int j=i;j<5;j++)

{

   if(card[i]==card[j])

   count[i]++;

}

}

int max3=0,max2=0,max1=0,max4=0;

for(int i=0;i<5;i++)

{

if(count[i]==3)

max3++;

else if(count[i]==2)

max2++;

else if(count[i]==1)

max1++;

else if(count[i]==4)

max4++;

}

if(max4==1)

{

max3--;

max2--;

max1--;

}

else if(max3==1)

{

max2--;

max1--;

}

if(max2==1)

{

max1--;

}

char temp;

for(int i=0;i<5;i++) // arranging card in order

{

for(int j=i+1;j<5;j++)

{

if(card[i]>card[j])

{ temp=card[j];

card[j]=card[i];

card[i]=temp;

}

}

}

  

int alpha=0; // to test the condition of stright flush

if(card[0]==2&&card[4]==6&&max4!=1)

alpha=1;

if(card[0]==3&&card[4]==7&&max4!=1)

alpha=1;

if(card[0]==4&&card[4]==8&&max4!=1)

alpha=1;

if(card[0]==5&&card[4]==9&&max4!=1)

alpha=1;

if(card[0]==6&&card[4]=='j'&&max4!=1)

alpha=1;

if(card[0]==7&&card[4]=='q'&&max4!=1)

alpha=1;

if(card[0]==8&&card[4]=='k'&&max4!=1)

alpha=1;

if(card[0]==2&&card[4]=='a'&&max4!=1)

alpha=1;

  

//cout<<" max3 "<<max3<<" max2 "<<max2<<" max1 "<<max1<<" max4 "<<max4;

if(max3==1&&max2==1)

cout<<"FULL House";

else if(alpha==1)

cout<<"straight flush";

else if(max4==1)

cout<<"Four of a kind";

else if(max3==1)

cout<<"three of a kind";

else if(max2==2)

cout<<"two piars";

else if(max2==1)

cout<<"pair";

cout<<" ";

return 0;

}

sample output

enter card and then its suit

2 d

2 s

2 c

2 h

3 d

Four of a kind

Program ended with exit code: 0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote