Archived

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

Quick Debugging Question. What is wrong here???

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
Share on other sites