基本的に私がコンパイルして実行すると、 "Begin combat !!"私のループに何が間違っているのか分かりません。このコードは、私の目にはまったく問題なく動作するはずですが、なぜ私に悪いビジョンがあるのかを理解する助けが必要です。私の単純なC++テキストゲームは動作しません。私は乱数を生成して使用しています。私は混乱しています
#include <iostream>
#include <ctime>
#include <random>
using namespace std;
int main() {
mt19937 randGen(time(NULL));
uniform_int_distribution<int> humanatt(4, 8);
uniform_int_distribution<int> humanhp(50, 100);
uniform_int_distribution<int> skelatt(12, 17);
uniform_int_distribution<int> skelhp(70, 85);
int hAtt, hHp, sAtt, sHp;
unsigned long humans, skeletons, deadHumans = 0, deadSkeletons = 0;
cout << "*** Skeletons vs Humans ***" << endl;
cout << "Input the number of humans: ";
cin >> humans;
cout << "Input the number of skeletons: ";
cin >> skeletons;
cout << "Beginning combat!!" << endl << endl << "(combat noises)" << endl;
while ((humans > 0) && (skeletons > 0)) {
hAtt = humanatt(randGen);
hHp = humanhp(randGen);
sAtt = skelatt(randGen);
sHp = skelhp(randGen);
while ((hHp > 0) && (sHp > 0)) {
if (hAtt >= sHp) {
skeletons--;
deadHumans++;
}
if (sAtt >= hHp) {
humans--;
deadHumans++;
}
}
}
cout << endl << "Combat has ended!" << endl << endl;
if ((humans == 0) && (skeletons == 0)) {
cout << "They all died!" << endl;
cout << "This was a battle with no winner" << endl;
cout << deadHumans + deadSkeletons << " men and bone-men, gave gave there lives this day";
}
else {
if (humans == 0) {
cout << "The Skeletons Win!" << endl;
cout << "They killed all " << deadHumans << " of the humans" << endl;
cout << "However, at the cost of " << deadSkeletons << " of they're own" << endl;
cout << "Only " << skeletons << " remain";
}
else {
cout << "The Humans Win!" << endl;
cout << "They killed all " << deadSkeletons << " of the humans" << endl;
cout << "However, at the cost of " << deadHumans << " of they're own" << endl;
cout << "Only " << humans << " remain";
}
}
system("PAUSE");
return 0;
}
ああ、私は汚いコードについて申し訳ありません。
私はあなたがデバッガを使用する方法を学ぶべきだと思います。これはコミュニティがあなたのコードがどこで壊れているかを推測させるよりもずっと効果的で正確です。 –