My newly revised code works this way.
Code:
#include <iostream>
using std::cout;
using std::left;
using std::right;
using std::endl;
#include <stdlib.h>
#include <iomanip>
using std::setw;
#include <cstdlib>
#include <ctime>
const int PLAYERS=2;
const int CARDS=5;
void shuffle( int[][13]);
void deal(int,int,int [PLAYERS][CARDS]);
void showhand(int [PLAYERS][CARDS],const int [][13], const char *[],const char *[]);
int main(int argc, char *argv[])
{
//initialize suit array
const char *suit[4]={"Hearts","Diamonds","Clubs","Spades"};
//initialize face array
const char *face[13]={"Ace","Deuce","Three","Four","Five","Six",
"Seven","Eight","Nine","Ten","Jack","Queen","King"};
//initialize deck array
int deck[4][13]={0};
int hands[PLAYERS][CARDS]={0};
srand(time(0));
shuffle(deck);
deal(PLAYERS,CARDS,hands);
showhand(hands,deck,face,suit);
system("PAUSE");
return 0;
}
//shuffle cards in deck
void shuffle(int wDeck[][13])
{
int row;
int column;
//for each of the 52 cards choose a slot of the deck randomly
for (int card=1;card<=52;card++){
do{
row=rand()%4;
column=rand()%13;
}while (wDeck[row][column] != 0);
wDeck[row][column]=card;
}
}
//deal cards in deck
void showhand(int tPlayers[PLAYERS][CARDS],const int wDeck[][13], const char *wFace[],const char *wSuit[])
{
int card=0;
//for each of the 52 cards
for (int player=0;player<=1;player++){
cout << "\nPlayer number "<<player<<endl;
for (int c=0;c<=4;c++)
for (int row=0; row<=3;row++)
for(int column=0;column<=12;column++)
if (wDeck[row][column]==tPlayers[player][c]) {
cout << setw(5)<<right<<wFace[column]
<< " of " << setw(8)<<left
<< wSuit[row]<<endl;
}
}
}
void deal(int tPlayers, int number_of_cards,int tHands[PLAYERS][CARDS])
{
if ((tPlayers*number_of_cards)>52){
cout << "There are only 52 cards in the deck!"<<endl;
return;
}
for (int i=0; i<((tPlayers*number_of_cards));i++){
tHands[i % tPlayers][i % number_of_cards]=i+1;
}
}