#### Archived

This topic is now archived and is closed to further replies.

# Quick Debugging Question. What is wrong here???

This topic is 5660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Here is my source

void dealcard(int towho, CCard* pDeck, CCard* pPlayerCard, int* pPlayertotal, int* pCputotal)
{
switch(towho)
{
case 1:
for(int i = 0; i < 10; i++)
{
if (pPlayerCard[i].suit == 0)
{
for(int j = 0; j < 52; j++)
{
if (pDeck[j].used = false)
{
pPlayerCard[i] = pDeck[j];
pDeck[j].used = true;
pPlayertotal += pPlayerCard[i].value;
return;
}
}
}
}
break;
case 2:
for(int k = 0; k < 52; k++)
{
if (pDeck[k].used = false)
{
pDeck[k].used = true;
pCputotal += pDeck[k].value;
}
}
break;
default:
cout<<"Error in Player# in Dealcard"<<endl;
exit(0);
break;
}
}

When I compile my program, this function is returning an error. It's saying ..
C:\My Documents\Black Jack\Blackjk.cpp(212) : error C2360: initialization of 'i' is skipped by 'case' label
C:\My Documents\Black Jack\Blackjk.cpp(195) : see declaration of 'i'

This makes me think that the for loop using the 'i' variable is not ending before the next case statement. But why is that? I've looked over this code for 10 minutes now and can't find a problem. Can you not use for statments inside case statemnents? Any help is appreciated. ~~~~~~~~~~~ Chris Vogel ~~~~~~~~~~~ [edited by - Radagar on August 26, 2002 4:37:14 PM]

##### Share on other sites
Try putting { and } around the code after your case labels.
Don''t ask me why, but it usually works.

/John

##### Share on other sites
I actually tried that before I posted, but I must of done it wrong. I just tried it again and it compiled. So thanks for the suggestion!

##### Share on other sites
You can''t declare variables inside a switch statement...
In your code, you have put "int i=0; " (in for loop). Just put i=0 and declare the variable ''i'' before switch...

##### Share on other sites
quote:
Original post by HiddenInBSP
You can''t declare variables inside a switch statement...
In your code, you have put "int i=0; " (in for loop). Just put i=0 and declare the variable ''i'' before switch...

Thanks for the Info HiddenInBSP, but the Previous posters suggestion worked.

##### Share on other sites
Well, really Hidden was wrong. It''s possible to declare variables within a case (and thus within a switch), if you place it also within a block (via {}).

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//