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

Final Project Intro to CSCI: Store deck of cards into an array. A,2,3,4,5,6,7,8,

ID: 3622643 • Letter: F

Question

Final Project Intro to CSCI:
Store deck of cards into an array.
A,2,3,4,5,6,7,8,9,0,J,Q,K
Hearts, Spades, Diamonds, Clubs
Once the deck of cards is stored, randomly select 5 cards. Store these cards into a separate array from the deck of cards. Figure out if you have a Flush (5 cards of same suit), or a Straight (5 cards in numerical order but not of same suit), or Three of a Kind, or Two of a Kind (possibly two pairs). Display cards and what your hand has earned either Flush, Straight, Three of a Kind or Two of a Kind.

I'm just beginning C++ and am stuck on my final project for my teacher for this semester.

So far what I've done:
#include <stdio.h>

#define ROWS 13
#define COLS 4

void readCardArray(const int [][], int);

int main(void)
{
int cont, i, drawCard;
int cards[ROWS][COLS];

//Explains what program does
printf("This program randomly selects five cards from a deck and displays if the cards selected have any value. ");
printf("Input a number to continue and randomly select five cards:");
scanf("%i", cont);

//Call function to read array for deck of cards
readCardArray(cards[][]);

//randomly select five cards


//Assign face and number value to numbers assigned


//Displays end result of five cards selected
printf("You drew: ", );
printf("The results of your hand is: ", );

return 0;

}


void readCardArray(int cards[ROWS][COLS])
{
int cards[ROWS][COLS] = {
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}
};
}

What I need help on:
1.) Randomly selecting 5 cards without picking the same one twice.
2.) Assigning a number and face value to each number in the 2D array.
3.) Selecting if the hand is a flush, straight, three of a kind, or two of a kind.
4.) Displaying results.

Explanation / Answer

please rate - thanks

should get you started

#include <iostream>
#include <ctime>
#include<iomanip>
using namespace std;
void shuffle(int[],int[]);
void dealcards(int[],int[],int[],int[],int&);
bool checkflush(int[]);
bool checkstraight(int[]);
void same(int [],bool &,bool &,bool &,bool &,bool &);
void winner(int[],int[],int&);
int main()
{
int i,j,flushes,decks[52],deckn[52],high=0,highowner=0;
int hands[5],handn[5],scored,count,cards=0,score[4],winners[4],numwin=0;
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;
srand(time(0));
scored=0;
shuffle(decks,deckn);
for(i=0;i<4;i++)
{
dealcards(hands,handn,decks,deckn,cards);
cout<<" Hand: "<<i+1<<" ";
       for(j=0;j<5;j++)
          cout<<card[handn[j]]<<" "<<suit[hands[j]]<<endl;
flush=checkflush(hands);
straight=checkstraight(handn);
same(handn,nothing,pair,pair2,three,four);
if(handn[5]>high)
    {high=handn[i];
    highowner=i;
}
cout<<"scoring: ";
if(straight&&flush)
     {cout<<"straight flush ";
      score[i]=1;
     }
else if(pair&&three)
      {cout<<"full house ";
       score[i]=3;
     }
else if(straight)
     {cout<<"straight ";
     score[i]=5;
     }
else if(flush)
     {cout<<"flush ";
      score[i]=4;
     }  
else if(four)
     {cout<<"four of a kind ";
      score[i]=2;
     }
else if(three)
     {cout<<"Three of a kind ";
      score[i]=6;
     }
else if(pair2)
     {cout<<"2 pair ";  
      score[i]=7;
     }         
else if(pair)
    {cout<<"one pair ";
    score[i]=8;
     }
else
    {cout<<"nothing ";
     score[i]=10;
     }     
}    
for(i=0;i<4;i++)
    if(highowner==i&&score[i]==10)
         score[i]=9;
cout<<" The winner is player(s) ";
winner(score,winners,numwin);
for(i=0;i<numwin;i++)
    cout<<winners[i]+1<<" ";
cout<<endl;
system("pause");
return 0;
}
void winner(int score[],int win[],int &w)
{int i,winning=0;
for(i=1;i<4;i++)
    if(score[i]<score[winning])
        {w=0;
         win[w++]=i;
         winning=i;
         }
    else if(score[i]==score[winning])
         win[w++]=i;

}

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 & cards)
{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++;
        }
for(i=0;i<4;i++)
     for(j=i+1;j<5;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;
             }
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;
}

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