Can some1 giv me some clues to cont the deal card to players part ??? The program will deal cards once the user enter the numbers of player between 3-7, either five cards per player or seven cards per player depending upon the menu selection, to the players at the table. The dealer, the program, always is dealt to last.
#include <iostream>
#include <string> // string
#include <ctime>
#include <iomanip>
#include <cstdlib>
using namespace std;
struct card{
char suit ;
char rank ;
}deck[52];
void GenerateRandom (card *ptrCard, int arraySize);
void Display (card *ptrCard, int arraySize);
void dealCard (card *ptrCard, int pNum, int cardSize);
const char *wSuit [] = {"Spades", "Hearts", "Clubs", "Diamonds"};
const char *wRank []= {"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
int main ()
{
card deck[52];
card *ptrCard = new card [52];
int num , playerNum, numSelect ;
srand (time (NULL));
do{
cout<<"1. Deal Five Cards"<<endl;
cout<<"2. Deal Seven Cards"<<endl;
cout<<"3. Quit the Game"<<endl;
cout<<endl;
cout<<"Enter Selection : "<<flush;
cin>>numSelect;
cout<<endl;
switch (numSelect){
case 1 : cout<<"You chosed deal five cards."<<endl;
cout << "\n\nGenerate Random Cards :\n\n";
num = 5;
break;
case 2 : cout<<"You Chosed deal seven cards."<<endl;
cout << "\n\nGenerate Random Cards :\n\n";
num = 7;
break;
case 3 : exit (1);
break;
default: cout<<" Wrong Selection. Please choose again !!! "<<endl;
cout<<endl;
}
}while (numSelect > 3 || numSelect <= 0);
GenerateRandom (ptrCard, 52);
Display (ptrCard, 52);
dealCard (ptrCard, playerNum, num);
delete [] ptrCard; // delete card array
system("pause");
return 0;
}
void GenerateRandom (card *ptrCard, int arraySize){
// this method will generate repeated random numbers. boolean array
// keeps track of what numbers have been picked. Generates another if
// this number has already been picked.
bool* picked = new bool[52];
// initialize 52 cards to unpicked
for (int i = 0; i < 52; i++)
picked[i] = false;
int value;
//assumes all the generated cards are different in location for every new game
for (int i = 0; i < arraySize; i++)
{
value = rand () % 52;
if (!picked[value])
{
ptrCard[i].rank = value;
ptrCard[i].suit = value; // card hasn't been picked then assign into array,
picked[value] = true; // flag as picked.
}
else
i--; // already picked.
}
delete [] picked;
}
void Display (card *ptrCard, int arraySize)
{
for (int i = 0; i < arraySize; i++)
{
cout <<right << setw( 3 ) <<i + 1<< ". "<< right << setw( 5 ) << wRank[ptrCard[i].rank % 13] << " of "
<< left << setw( 8 ) <<wSuit[ptrCard[i].suit % 4]<< ( (i + 1) % 2 ? '\t' : '\n' ) ;
}
}
void dealCard (card *ptrCard, int pNum, int cardSize)
{
do{
cout<<"Enter the players Number: "<<flush;
cin>>pNum;
}while (pNum < 3 || pNum > 7);
int cardRange = pNum * cardSize;
int *player = new int[pNum];
/****************
for (i=0; i<pNum ; i++)
{ ***HOW TO PASS GENERATED RANDOM CARDS TO THE PLAYERS ???
player[i]
} ************/
for (int i=0 ; i < cardRange; i++)
{
cout <<right << setw( 3 ) <<i + 1<< ". "<< right << setw( 5 ) << wRank[ptrCard[i].rank % 13] << " of "
<< left << setw( 8 ) <<wSuit[ptrCard[i].suit % 4]<< ( (i + 1) % cardSize ? '\t' : '\n' ) ;
}
cout<<endl;
delete [] player;
}