我的程序似乎运行正常但在某些点上变量healthone似乎也被添加,而不是像它应该被减去的那样虽然在这段代码中没有添加到healtone的行。
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
int main()
{
float healthone, healthtwo, ending;
int attack, move, random, chance, comprandom, attackp, attackcp, rando;
char c;
string comattackname;
cout << "Do you want to be Naruto or Goku? [n or g]: ";
cin >> c;
cout << " n";
cout << "Naruto and Goku enter the ring!" << endl;
cout << " n";
healthone = 23;
healthtwo = 23;
ending = 10;
while (ending >= 0) {
if (c == 'n') {
cout << "What move do you want to use?" << endl;
cout << "1 - Tail Beast Bomb" << endl;
cout << "2 - Rasengan Shurikan Barrage" << endl;
cout << "3 - Giant Rassengan Barrage" << endl;
cout << "4 - Rassengan Barrage" << endl;
cout << "5 - Rassengan Shuriken" << endl;
cout << "6 - Rasengan" << endl;
cout << "7 - Direct Punch" << endl;
cout << "8 - Shuriken" << endl;
cout << "9 - Enter Sage Mode" << endl;
cout << "10 - Enter Limited Tail Beast Mode" << endl;
cout << "11 - Enter 9 Tails Mode" << endl;
cout << "-";
cin >> move;
}
if (c == 'g') {
cout << "What move do you want to use?" << endl;
cout << "1 - Universal Spirit Bomb" << endl;
cout << "2 - Super Spirit Bomb" << endl;
cout << "3 - Continuos Kamehameha" << endl;
cout << "4 - Super Kamehameha" << endl;
cout << "5 - Kamehameha" << endl;
cout << "6 - Destructo Disk" << endl;
cout << "7 - Direct Punch" << endl;
cout << "8 - Ki Blast" << endl;
cout << "9 - Enter Sage Mode" << endl;
cout << "10 - Enter Limited Tail Beast Mode" << endl;
cout << "11 - Enter 9 Tails Mode" << endl;
cout << "-";
cin >> move;
}
if (move == 8) {
attackp = 1;
rando = 23;
}
if (move == 7) {
attackp = 2;
rando = 17;
}
if (move == 6) {
attackp = 3;
rando = 12;
}
if (move == 5) {
attackp = 5;
rando = 8;
}
if (move == 4) {
attackp = 8;
rando = 5;
}
if (move == 3) {
attackp = 12;
rando = 3;
}
if (move == 2) {
attackp = 17;
rando = 2;
}
if (move == 1) {
attackp = 23;
rando = 1;
}
chance = 1 + rand() % 23;
if (chance <= rando) {
cout << " " << endl;
cout << "Hit! Dealing " << attackp << " Damage!" << endl;
healthtwo = healthtwo - attackp;
} else {
cout << " " << endl;
cout << "Miss!" << endl;
}
comprandom = 1 + rand() % 8;
if (comprandom == 8) {
attackcp = 1;
rando = 23;
}
if (comprandom == 7) {
attackcp = 2;
rando = 17;
}
if (comprandom == 6) {
attackcp = 3;
rando = 12;
}
if (comprandom == 5) {
attackcp = 5;
rando = 8;
}
if (comprandom == 4) {
attackcp = 8;
rando = 5;
}
if (comprandom == 3) {
attackcp = 12;
rando = 3;
}
if (comprandom == 2) {
attackcp = 17;
rando = 2;
}
if (comprandom == 1) {
attackcp = 23;
rando = 1;
}
if (c = 'n') {
if (comprandom == 1) {
comattackname = "Tail Beast Bomb";
}
if (comprandom == 2) {
comattackname = "Rasengan Shurikan Barrage";
}
if (comprandom == 3) {
comattackname = "Giant Rassengan Barrage";
}
if (comprandom == 4) {
comattackname = "Rassengan Barrage";
}
if (comprandom == 5) {
comattackname = "Rassengan Shuriken";
}
if (comprandom == 6) {
comattackname = "Rasengan";
}
if (comprandom == 7) {
comattackname = "Direct Punch";
}
if (comprandom == 8) {
comattackname = "Shuriken";
}
} else if (comprandom == 1) {
comattackname = "Universal Spirit Bomb";
}
if (comprandom == 2) {
comattackname = "Super Spirit Bomb";
}
if (comprandom == 3) {
comattackname = "Continuos Kamehameha";
}
if (comprandom == 4) {
comattackname = "Super Kamehameha";
}
if (comprandom == 5) {
comattackname = "Kamehameha";
}
if (comprandom == 6) {
comattackname = "Destructo Disk";
}
if (comprandom == 7) {
comattackname = "Direct Punch";
}
if (comprandom == 8) {
comattackname = "Ki Blast";
}
chance = 1 + rand() % 23;
if (chance <= rando) {
cout << "Comp Used " << comattackname << "!" << " Hit!" << " Dealing " << attackcp << " Damage" << endl;
cout << " " << endl;
healthone = healthone - attackcp;
} else {
cout << "Comp Used " << comattackname << "!" << " Miss!" << endl;
cout << " " << endl;
}
cout << "Your health: " << healthone << endl;
cout << "Comp health: " << healthtwo << endl;
cout << " " << endl;
if (healthone > healthtwo) {
ending = healthone;
}
if (healthone < healthtwo) {
ending = healthtwo;
}
if (healthone = healthtwo) {
ending = healthone;
}
if (healthone <= 0) {
cout << "You loose." << endl;
cout << " " << endl;
}
if (healthtwo <= 0) {
cout << "You win." << endl;
cout << " " << endl;
}
}
}
答案 0 :(得分:3)
这一行是你的问题:
if (healthone=healthtwo)
{
ending=healthone;
}
将其更改为:
if (healthone==healthtwo)
{
ending=healthone;
}
我不知道您的IDE,但其中许多人会将此类标记为警告。检查你的警告......