Quote Originally Posted by wipeout4wh View Post
The index is just the part of an array that's in square brackets, right?

If I do that, it would still reuse the cards that are still in play when I reshuffle the deck. If I have a 5 in my hand, there should only be 3 5's in the deck when it gets reshuffled. That means I would need to remove the card from the deck and add it to a discard pile when it's out of play.
So reshuffle not when you reach the last card, but when you don't have enough cards to play a full hand. It would not be fair to reshuffle in the middle of a hand.

Edit: I decided to have it shuffle the deck first like you guys said. Here's drawCard() so far:

Code:
int drawCard() {

    static int deck[52] = {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13};
    static int cardToDraw = 0;
    int drawnCard;

    if (cardToDraw < 52) {
        drawnCard = deck[cardToDraw];
        deck[cardToDraw] = 0;
        cardToDraw++;
    }
    else {
        shuffleDeck();
        cardToDraw = 0;
    }

    cout<< "cardToDraw = "<< cardToDraw<< ".\n";//Debugging line.
    return drawnCard;
}
I'll have to learn about passing variables between functions, and I haven't written shuffleDeck() yet, but does this look good so far?

Edit: Would it be better to just set deck[52] as a global variable? I don't really understand how to pass variables between functions. I wrote part of shuffleDeck(), but I can't continue until I figure this out.

Code:
void shuffleDeck() {

    int firstCard;
    int secondCard;
    int i;

    for (i = 0; i < 100; i++){
        firstCard = (rand() % 52);
        secondCard = (rand() % 52);
        
    }
}
I wish you knew pointers, because then I could tell you about std::random_shuffle().

The first like of shuffleDeck should look like this. Because deck is an array, modifying it in shuffleDeck will modify it in the original.
Code:
void shuffleDeck(int deck[52])
To call it simply do:
Code:
shuffleDeck(deck)
Also, you don't need to make your first card random, as long as your second card is. then you can loop from 0 to 52 (i<52), and know that every card has been swapped at least once.