help with bool and const int array

Hey I got this program to create an array of playing cards and assign the values and suits and shuffle the array. I'm at the point where I need to output the cards but I need to burn the first card by making it output "**" instead of the card. my cards[] is a constant so I can's assign the first card as such. Any ideas how I can make this work?

1
2
3
4
5
6
7
8
9
10
11
12
13
void showCards(const int cards[], int numCards, bool hideFirstCard)
{
	if (cards[0])
	{
	hideFirstCard=true;
	cards[0] = '**';
	}

	for(int a = 0; a <= numCards; a++)
	{
		cout >> showCard(cards[a]);
	}
}
Last edited on
Could you not just output ** to the console and then start your for-loop at a = 1?
Yea I could but the problem is I have to use the bool parameter to set the first card to asterisks. I do not know why we are doing it like this but I think it is to develop a black jack game later.
Not much you can do then. You can't actually change the value of card[0] to '**' for two reasons.

1) '**' is not an int type, so you would have a conversion error.
2) Even if you used an int, the fact that you're passing cards[] as a const means you absolutely cannot change its value.

My only suggestion would be to check the bool hidFirstCard in the for-loop. If it is false, then you would output '**' to the console and change its value. If it is true, then you would output the card like normal.
Yeah your right I may have been thinking about it wrong. I now I have this set up for it and it works but the problem I have now is that it outputs all the cards but the last card value is missing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if (hideFirstCard==true)
	{
		cout << "**";
		
		for(int a = 1; a <= numCards; a++)
		{ 
			showCard(cards[a]);
		}
	}

	if (hideFirstCard == false)
	{
		for(int a = 0; a <= numCards; a++)
		{ 
			showCard(cards[a]);
		}
	}
Your problem in that snippet of code is that arrays are indexed from [0, Number of elements - 1]. Your loops go from [x, Number of elements], so you're extending beyond the bounds of the array by 1.
got it I understand that. I've changed the code but I'm still getting the problem of some not showing the value I assigned but it still shows the suit. I have no idea why that is, it looks like on the output window when it goes to a new line it cuts it off for some reason. I gotta tweek it some more obviously but thanks a lot for the help Keene, I greatly appreciate it.
Topic archived. No new replies allowed.