-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)の例と、その問題を再現するためのデバッガ。 –