Difficulty With char_create() function?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int char_create()
{
	cout << "Hello! What's your name?" << endl;
	cout << ">";
	getline(cin, username);
	cout << "Hello " << username << endl;
	cout << "What class are you?" << endl;
	cout << "1: Warrior (High attack and defense)" << endl;
	cout << "2: Archer (Well rounded)" << endl;
	cout << "3: Mage (High crafting and intelligence)" << endl;
	cin >> input_int;
		switch(input_int)
			case 1:
				userclass = "Warrior";
			case 2:
				userclass = "Archer";
			case 3:
				userclass = "Mage";
	ofstream character_data((username + ".txt").c_str());
	character_data << username << endl;
	character_data << userclass << endl;
	return 0;
}


This function is giving me an illegal use of case for cases 2 and 3?

Sorry for all my questions I am still getting used to Visual Studio 2010. Big jump from Dev-C++. There will probably be a few more questions so I am going to just keep this post open for them.
Last edited on
You need to put everything in the switch inside curly brackets
1
2
3
4
5
6
7
8
9
switch(input_int)
{
case 1:
	userclass = "Warrior";
case 2:
	userclass = "Archer";
case 3:
	userclass = "Mage";
};
Thank you I can't believe I forgot that XD
And may be use break ... in your switch case.
Already on that. Added it after I posted this lol.
Topic archived. No new replies allowed.