maybe i missed this being answered in another question but after searching i can't seem to find the answer i need.
here is the code i am using to deal cards as it stands which correctly changes the first two card values to random ints from the deck array. however as it is written, the code occasionally passes duplicate values into the player hand.
void Deal()
{
for (int i = 0; i < 2; ++i)
{
playerHand[i] = deck[i];
dealerHand[i] = deck[i + 2];
if (playerHand[i] == 11)
{
cout << "BLACKJACK!! YOU WIN!!" << endl;
WinHand();
}
else if (dealerHand[i] == 11)
{
cout << "Dealer Got Blackjack. Hand goes to dealer." << endl;
}
else
{
playerNextCard++;
dealerNextCard++;
deckNextCard = 4;
}
}
for (size_t i = 0; i < 2; i++)
{
cout << playerHand[i] << endl;
}
cout << "? \n" << dealerHand[1] << endl;
cout << "Money: " << money << endl;
return;
}
The Player, and Dealer are always receiving the first four cards unless an 11 is drawn where it terminates early. Whether, or not the deck is shuffled there is a possibility to receive a duplicate integer. If you want to make each draw integer unique then you can search the deck until the previous one does not match. You will also have to consider what happens if no unique integer is found.