Switch structure not working

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
case 2:
		int roll = Random(1, 4);

		if (roll == 1)
		{
			cout << "You run away!" << endl;
			return true;
		}
		else 
		{
			cout << "You could not escape." << endl;
			return false;
		}

	default:
		cout << "Wrong selection." << endl;
		return false;


Error: error C2361: initialization of 'roll' is skipped by 'default' label

I have checked the {} and they seem to be okay. What is wrong with this?

Thanks
Try putting a break; before your default: label
Hey,

I've tried that already but it didn't work :(
Enclose the scope of 'roll' into braces:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
case 2:
     {//
		int roll = Random(1, 4);

		if (roll == 1)
		{
			cout << "You run away!" << endl;
			return true;
		}
		else 
		{
			cout << "You could not escape." << endl;
			return false;
		}
     }// now roll is out of scope
	default:
		cout << "Wrong selection." << endl;
		return false;
That works fine, thank you Bazzy :)
Topic archived. No new replies allowed.