-3
사용자가 콘솔에 올바른 문자열을 넣은 다음 올바른 if 문과 연관시키는 방법을 잘 모릅니다. 또한 민첩성, 힘, 지능에 피해 값이나 방어구 값을 할당하여 캐릭터가 정수가 아닌 다른 캐릭터에 영향을 주는지 확신 할 수 없습니다. 모든if 문을 사용하여 사용자가 올바른 문자열을 넣었는지 확인하십시오.
if (Charactertype.type == "Warrior","warrior")
의
class Character {
public:
string name;
string gender;
string type;
int strength;
int agility;
int intelligence;
int level;
int health;
int experience;
int mainweapon;
int offhand;
int chest;
int legarmor;
int gloves;
int helmet;
int gold;
int faction;
};
int main()
{
Character Charactername;
Character Charactergender;
Character Charactertype;
Character Characteragility;
Character Characterstrength;
Character Characterintelligence;
cout << "what is your name?\n";
cin >> Charactername.name;
cout << "Male or Female\n";
cin >> Charactergender.gender;
cout << "What class are you, Warrior, Mage or Rogue\n";
cin >> Charactertype.type;
cout << "Welcome to the Elysium " << Charactername.name;
Sleep(5000);
Character Characterhealth;
Characterhealth.health = 100;
if (Charactertype.type == "Warrior","warrior")
Characteragility.agility = 6, Characterstrength.strength = 10, Characterintelligence.intelligence = 4;
else if (Charactertype.type == "Mage","mage")
Characteragility.agility = 4, Characterstrength.strength = 6, Characterintelligence.intelligence = 10;
else if (Charactertype.type == "Rogue", "rogue")
Characteragility.agility = 10, Characterstrength.strength = 4, Characterintelligence.intelligence = 6;
else cout << "you have entered a invalid name" << main;
cout << Characteragility.agility << endl << Characterstrength.strength << endl << Characterintelligence.intelligence;
Sleep(2000);
};
좋은 책을 사서 읽어보십시오. 당신은 분명히 당신이 무엇을하고 있는지 이해하지 못합니다. – Starl1ght
'if (Charactertype.type == "Warrior", "warrior")'는 당신이 생각하는대로하지 않습니다. –
이러한 문제를 해결하는 올바른 도구는 디버거입니다. 스택 오버플로를 묻기 전에 코드를 단계별로 실행해야합니다. 자세한 도움말은 [작은 프로그램 디버깅 방법 (Eric Lippert 작성)] (https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)을 참조하십시오. 문제를 재현하는 [최소, 완료 및 확인 가능] (http://stackoverflow.com/help/mcve) 예제와 함께 해당 질문을 \ [편집]해야합니다. 디버거. –