I am completely new to C++. I have a function that deals cards for a blackjack game. To do this, I need to call this function 10 times (two cards each for 4 players and a dealer). But it just deals the same card to everyone. I think it might be because I seeded srand() with time(), and then call the function many times within the same second, but that's how I need it to operate. Here's a stripped down version of my code:
void deal_card(int &suit, int &value) {
srand(time(NULL));
int num_cards = 3;
int randIndex;
srand(time(NULL));
randIndex = rand() % num_cards;
int deck[][2] = {{1, 2}, {1, 3}, {1, 4}};
suit = deck[randIndex][0];
value = deck[randIndex][1];
}
int main() {
int bs, bv, as, av, cs, cv;
deal_card(bs, bv);
cout << bs << " " << bv << endl;
deal_card(as, av);
cout << as << " " << av << endl;
deal_card(cs, cv);
cout << cs << " " << cv << endl;
return 0;
}
Of course with #include <iostream> and <cstdlib>.
Can someone help me deal 3 RANDOM cards? As a side issue, I'm not sure how to remove a card from deck[] after it's been dealt to ensure no two player get the exact same card. I'm sure my code is sloppy, but this is a project to help me learn. Thanks.