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

Poker Game (C++ CODE ONLY) First input line should be single integer n, which re

ID: 3804281 • Letter: P

Question

Poker Game (C++ CODE ONLY) First input line should be single integer n, which represents number of rounds. There are n lines per rounds. For each round you are given 10 cards. The first five for Player 1 and next 5 for player 2, for example 9A 8S 6C QH etc. The values of the cards in order are 2 345 6789 TJQKA, with the suits being S CHD. Output: If player 1 wins, say PLAYER 1 If player 2 wins, say PLAYER 2. TIE if none wins. How to win: 1. STRAIGHTFLUSH is when you get a full set of consecutive cards with all being the same suit 2. FOUR OF A KIND is when a set of 4 cards have the same value 3. FULL HOUSE is when there are three cards of one value and two of another 4. TWO PAIRS is a set of two different pairs 5. HIGHEST CARD is simply whoever has the highest card wins the round; if not, then the next highest.

Explanation / Answer

#include<iostream>
#include<cstdlib>
#include<string>
#include<ctime>
using namespace std;
int main()
{
    srand(time(0));
    int i,j,deck[52],cardno,card,currval,c[5],d[5];
    string cardty[4]={"Hearts","Clubs","Diamonds","Spades"};
    string cardnam[13]={"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
    for(i=0;i<52;i++)
    {
        deck[i]=i;
    }
    for(i=0;i<52;i++)
    {
        j=rand() % 52;
        int temp=deck[i];
        deck[i]=deck[j];
        deck[j]=temp;
    }
    for(i=0;i<52;i++)
    {
        cardno=deck[i]/13;
        card=deck[i]%13;
        cout<<cardnam[card]<<"of"<<cardty[cardno]<<" ";
    }
    cout<<endl;
    int counter[ 13 ] = { 0 };
   int t; /* loop counters */
   for (i = 0; i<5; i++ )
   {
        c[5]++;
        for(t=0; t<13; t++ )
        {
        if(counter[t] == 4)
            cout<<"The hand contains three"<<cardty[cardno]<<" ";
        }
   }
    cout<<endl;
    for(i=0;i<5;i++)
    {
        int ace=0;
        currval=deck[i]%3;
        if(currval==ace)
        {
            cout<<"Ace Card"<<endl;
        }
    }
    for(i=0;i<5;i++)
    {
        c[5]=deck[i]%13;
        d[i]=deck[i]/13;
    }
    bool swap=false;
    do
    {
        swap=false;
        for(int i=0;i<4;i++)
        {
        if(c[5]>c[i+1])
        {
            int temp=c[i];
            c[i]=c[i+1];
            c[i+1]=temp;
            swap=true;
        }
        }
    }
        while(swap==true);
        for(int i=0;i<5;i++)
        {
        cout<<cardnam[c[i]]<<"of"<<cardty[d[i]]<<" ";
        }
        if(c[1]==c[0]+1 && c[2]==c[1]+1 && c[3]==c[2]+1 && c[4]==c[3]+1)
            cout<<"You got Straight"<<endl;
        else
            cout<<"Nothing"<<endl;
            if(c[0]==c[1]||c[1]==c[2]||c[2]==c[3]||c[3]==c[4])
                cout<<"You got a pair"<<endl;
            else
                cout<<"No pair"<<endl;
system("Pause");
return 0;
}