我對C++相當陌生。作爲一個項目,我重寫了一個我用python編寫的小遊戲(我從來沒有正確使用它)。在編譯過程中,我得到這個錯誤:錯誤:'operator- ='不匹配''C++錯誤:'operator- ='不匹配'
我知道這個運算符存在於C++中,所以爲什麼我會得到這個錯誤?
代碼:
void rpg() {
cout << "This mode is not yet complete. It only contains a dungeon so far. I'm still working on the rest!";
dgn();
}
void dgn() {
int whp = 100;
int mahp = 100;
int hhp = 100;
string m;
int mhp;
cout << "There are three passages. Do you take the first one, the second one, or the third one? (Give your answer in numbers)";
int psg;
cin >> psg;
switch (psg) {
case 1:
m = "Troll";
mhp = 80;
break;
case 2:
m = "Goblin";
mhp = 35;
break;
case 3:
m = "Dragon";
mhp = 120;
}
cout << "A ";
cout << m;
cout << " appears!";
dgnrd(m, mhp, whp, mahp, hhp);
}
void dgnrd(string m, string mhp, int whp, int mahp, int hhp) {
bool alive = true;
while (alive) {
string wa;
string ma;
string ha;
cout << "What does Warrior do? ";
cin >> wa;
cout << "What does Mage do? ";
cin >> ma;
cout << "What does Healer do? ";
cin >> ha;
if (wa == "flameslash") {
cout << "Warrior used Flame Slash!";
mhp -= 20;
}
else if (wa == "dragonslash" && m == "Dragon") {
cout << "Warrior used Dragon Slash!";
mhp -= 80;
}
else if (wa == "dragonslash" && (m == "Troll" || m == "Goblin")) {
cout << "Warrior's attack did no damage!";
}
if (ma == "icicledrop") {
cout << "Mage used Icicle Drop!";
mhp -= 30;
mahp -= 10;
whp -= 10;
hhp -= 10;
}
else if (ma == "flamesofhell") {
cout << "Mage used Flames of Hell!";
mhp -= 75;
mahp -= 50;
whp -= 50;
hhp -= 50;
}
else if (ma == "punch") {
cout << "Mage used Punch!";
mhp -= 5;
}
}
}
元音。不要害怕他們。 – DanielKO