Switch in a Switch problem

Hello and thank you for reading/responding.i keep geting this error on my IDE (dev C++) "duplicate label 'case 1'" i assume it is because I put a switch case in a switch case. is this legal? and if it is illegal how else can i write it to have the same effect? thank you for feed back!!!

example

switch(x)
{
case1;
switch(y)
{
case1:
//code
break;
case2:
//code
break;
case3:
//code
break;
}
case2:
switch(z)
{
case1:
//code
break;
case2:
//code
break;
case3:
//code
break;
}
}
1. It is case 1: not case1:. Leave space between the keyword and 1.
2. Avoid typographical error. Observe Line3. Change case1; to case 1:
3. Reformat your code to readable form
4. Use appropriate tags while posting.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
int main()
{
	int x = 0, y = 0, z = 0;
	switch(x)
	{
	case 1:
			switch(y)
			{
				case 1:
				//code
				break;
				case 2:
				//code
				break;
				case 3:
				//code
				break;
			}
		case 2:
			switch(z)
			{
				case 1:
				//code
				break;
				case 2:
				//code
				break;
				case 3:
				//code
				break;
			}
	}
	return 0;
}

The above code will compile.

Learn about switch statement in this article

http://www.cplusplus.com/doc/tutorial/control.html
Last edited on
Thanks for the help! i can't belive i missed something so obviuos and simple.
Topic archived. No new replies allowed.