So I took a break from programming for a few months and am back at it. I am attempting to make a function that will shuffle a deck of cards (52) to 4 players. I have setup a 2d array (myDeal[4][52]) and set all values to 0 for the time being. I select the random card by using rand()%52. If the value is available for the current player, ie myDeal[1][22] I am setting the value to 1 to show that it is there. The problem I am having is that my code seems to be getting stuck within a loop for no reason that I can see, but like I said I am a bit rusty on my programming currently.
void myDeal()
{
int myDeal[4][52] = {0,0};
int p = 0; // Player Index
int d = 0; // Deck Index
int card; // Card Number (0-52)
// Seed Random Generator
srand((unsigned)time(NULL));
for (d = 0; dIndex < 52; d++)
{
for(p = 0; pIndex < 4; p++)
{
bool result;
do
{
card = rand()%52;
if (myDeal[0][card] == 1)
result = false;
else if (myDeal[1][card] == 1)
result = false;
else if (myDeal[2][card] == 1)
result = false;
else if (myDeal[3][card] == 1)
result = false;
else
result = true;
}while (result == false);
myDeal[p][card] = 1;
}
}
}
I know I could use just one If, but since it has been giving me problems, I have broken it up for now.
It's just driving me insane, so any little help you can give is much appreciated.
Thanks