I'm programming a simple text-based RPG using a switch statement for a game loop. The program works fine until I attempt to add another case statement, at which point it gives me the following three errors: "jump to case label" (error occurs at the line of the newly added case), and two "crosses initialization of 'ClassName *objectName'"(errors occur when the new objects are created in case 2). I'll paste the important code, if anyone needs more, please let me know.
int main(void)
{
// add weapons to array
Weapon *weaponList[12];
// Rusty Sword
weaponList[0] = new Weapon(0,0,0);
weaponList[0]->SetAll(0,2,3);
// Bronze Sword
weaponList[1] = new Weapon(0,0,0);
weaponList[1]->SetAll(1,5,10);
// Bronze Battle Axe
weaponList[2] = new Weapon(0,0,0);
weaponList[2]->SetAll(2,15,30);
// Iron Sword
weaponList[3] = new Weapon(0,0,0);
weaponList[3]->SetAll(3,25,70);
// add armor to array
Armor *armorList[12];
// Worn Platemail
armorList[0] = new Armor(0,0,0);
armorList[0]->SetAll(0,2,3);
// Bronze Chainmail
armorList[1] = new Armor(0,0,0);
armorList[1]->SetAll(1,5,8);
// Bronze Platemail
armorList[2] = new Armor(0,0,0);
armorList[2]->SetAll(2,7,20);
// Iron Chainmail
armorList[3] = new Armor(0,0,0);
armorList[3]->SetAll(3,15,60);
while(gamestate != 8)
{
switch(gamestate)
{
case 0:
cout << " /| Welcome!\n"
<< " || \n"
<< " || \n"
<< " || \n"
<< "_||_ \n"
<< " 88 \n"
<< " 88 Name: ";
cin >> heroName;
gamestate = GAME_STATE_MENU;
break;
case 1:
cout << "\n"
<< "'/stats' will show you your stats\n"
<< "'/shop' will let you visit the weapon shop\n"
<< "secret commands: /setweapon # /setarmor # /setheroexp #\n"
<< "\n";
cout << "Command: ";
cin >> command;
if (strcmp(command, "/stats") == 0)
{
gamestate = 2;
break;
}
else if (strcmp(command, "/shop") == 0)
{
gamestate = 3;
break;
}
else if (strcmp(command, "/fight") == 0)
{
gamestate = 4;
break;
}
else if (strcmp(command, "/setweapon") == 0)
{
cin >> testNum;
heroWeapon = testNum;
break;
}
else if (strcmp(command, "/setarmor") == 0)
{
cin >> testNum;
heroArmor = testNum;
break;
}
else if (strcmp(command, "/setheroexp") == 0)
{
cin >> testNum;
heroExp = testNum;
LevelUp();
break;
}
else if (strcmp(command, "/exit") == 0)
{
gamestate = 8;
break;
}
else
{
cout << "Please enter a valid command.\n";
gamestate = 2;
break;
}
case 2:
Weapon *wCurrent = weaponList[heroWeapon];
Armor *aCurrent = armorList[heroArmor];
heroWeaponPower = wCurrent->GetWeaponAttack();
heroArmorDefense = aCurrent->GetArmorDefense();
heroPowerDefault = ((heroLevel - 1) * 10) + 10;
heroPower = heroPowerDefault + (heroStrength * 2) + heroWeaponPower;
heroDefenseDefault = ((heroLevel - 1) * 2) + 5;
heroDefense = heroDefenseDefault + (heroAgility / 5) + heroArmorDefense;
heroHealthDefault = (heroLevel * 5) + 20;
heroHealth = heroHealthDefault + (heroStamina * 10);
cout << "\nS T A T S\nName: "
<< heroName
<< "\nLevel: "
<< heroLevel
<< "\nExp: "
<< heroExp << "/" << expForLevel[heroLevel]
<< "\nGold: "
<< heroGold
<< "\nHealth: "
<< heroHealth
<< "\nPower: "
<< heroPower
<< "\nDefense: "
<< heroDefense
<< "\nWeapon: "
<< weaponNameList[heroWeapon]
<< "\nArmor: "
<< armorNameList[heroArmor]
<< "\n\n";
system("PAUSE");
gamestate = 2;
break;
case 3:
break;
}
}
return 0;
}