-1
私はコマンドラインゲームを作ろうとしていますが、私はこれらの2つの関数を宣言していますが、playerAttack();
を呼び出すと、error: playerAttack start was not declared in this scope
というメッセージが表示されます。int main() {...}
関数の前に関数playerAttack()
とcpuAttack()
が宣言されています。事前にお手伝いしてください。C++関数が宣言されていませんか?
void cpuAttack() {
if (playerHealth > 0 && cpuHealth > 0) {
cout << "Attack Direction (left, right, or center): ";
cin >> attack;
cout << name << " attacks from the " << attack << endl;
srand(time(0));
cpuBlock = attDir[rand() % 2];
cout << "CPU-1 blocks the " << cpuBlock << endl;
if (attack != cpuBlock) {
cpuHealth - dmg;
} else {cpuHealth = cpuHealth - (dmg + 20);}
playerAttack();
} else if (playerHealth > 0 && cpuHealth <= 0) {
cout << "\n" << name << " has won the game.\n";
} else if (playerHealth <= 0 && cpuHealth > 0) {
cout << "\nCPU-1 has won the game.\n";
}
}
と
void playerAttack() {
if (playerHealth > 0 && cpuHealth > 0) {
cout << "Attack Direction (left, right, or center): ";
cin >> attack;
cout << name << " attacks from the " << attack << endl;
srand(time(0));
cpuBlock = attDir[rand() % 2];
cout << "CPU-1 blocks the " << cpuBlock << endl;
if (attack != cpuBlock) {
cpuHealth - dmg;
} else {cpuHealth = cpuHealth - (dmg + 20);}
cpuAttack();
} else if (playerHealth > 0 && cpuHealth <= 0) {
cout << "\n" << name << " has won the game.\n";
} else if (playerHealth <= 0 && cpuHealth > 0) {
cout << "\nCPU-1 has won the game.\n";
}
}
'main'の前に' playerAttack'を宣言しましたが、 'cpuAttack'の前に宣言しましたか? – immibis
@immibis 'cpuAttack'の前に宣言すると'エラー:cpuAttackはこのスコープで宣言されていません 'と表示されます。 –