Quick Debugging Question. What is wrong here???

Started by
4 comments, last by Radagar 21 years, 8 months ago
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]
WyrmSlayer RPG - In Early Development
Advertisement
Try putting { and } around the code after your case labels.
Don''t ask me why, but it usually works.

/John
/John
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!
WyrmSlayer RPG - In Early Development
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...
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.


WyrmSlayer RPG - In Early Development
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.//
miscellaneous links

[twitter]warrenm[/twitter]

This topic is closed to new replies.

Advertisement