I’m new to programming and I have some issue with my code:
I’m not really sure how that thing is called so it’s hard to google it;
But I think human being will understand what I mean:
The while loop is increased by i++ each time. In the commented line I want to express
When
i = 1 , player1.cards[j] = random;
i = 2 , player2.cards[j] = random;
void cardScramble()
{
int random;
int i = 1;
while (i <= 4)
{
cout << "Card of Player " << i << " : ";
int j = 0;
while (j < 13)
{
random = rand() % 52;
if (cards[random] == NULL)
{
cards[random] = i;
cout << cardName(random) << " , ";
/* player(i).cards[j] = random; */
/* That's what I'm doubt with */
j++;
}
}
cout << endl;
i++;
}
return;
}
I tried to define it or manipulate it as a string but didn’t work.
Anyone can help me on this? Thanks a lot!
You cannot do it the way you are thinking of. Instead, combine
player1andplayer2(and any other players) into an array. For example:Then you can refer to each player using
ilike this:Or, if you want to start
iat 1, then just subtract 1 from it: