Ich versuche, ein Kommandozeilen-Spiel zu machen, und ich diese beiden Funktionen deklarieren, aber wenn ich playerAttack();
aufrufen die Build-Nachricht sagt error: playerAttack start was not declared in this scope
ich die Funktionen und cpuAttack()
vor der int main() {...}
Funktion, wenn das hilft. Bitte helfen Sie im Voraus.C++ Funktionen nicht deklariert?
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";
}
}
und
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";
}
}
Sie haben "playerAttack" vor 'main' deklariert, sagen Sie, aber haben Sie es vor' cpuAttack' deklariert? – immibis
@immibis wenn ich es vor 'cpuAttack' deklariere, bekomme ich' Fehler: cpuAttack wurde in diesem Bereich nicht deklariert'. –