I am currently making my first text adventure game and have come across a dilemma. I can't seem to find out what is going on. It's a runtime error and I have isolated it to this part of my code. When I run it and enter '1' for the if statement, it prints blank screens. Any help is appreciated. Thanks!
int choiceTwoStay=0;
cout << "*What would you like to do?" << endl;
cout << "\t >> Enter '1' to attack zombie with bat" << endl;
cout << "\t >> Enter '2' to attack zombie with tampons" << endl;
cout << "\t Enter '3' to cower because you are a pussy" << endl;
cin >> choiceTwoStay;
if (choiceTwoStay==1) {
string weaponChoice = "bat";
int zombieAHealth=30;
system("clear");
while(zombieAHealth>0); {
cout << "Press enter to attack" << endl;
cout << "..." << endl;
cin.ignore();
cin.get();
system("clear");
cout << endl;
srand(time(0));
int damageZombieA = rand()%(30-0 + 1) + 0;
cout << "# You hit him with " << weaponChoice << " and do " << damageZombieA << " damage!" << endl;
zombieAHealth=-damageZombieA;
cout << "Zombie Health: " << zombieAHealth;
}
}
Remove the semi-colon on 13.
Also, move the srand command out of the while loop. You could put it right after line 1.
Your not subtracting damageZomieA from zombieAHealth, but assigning it with a minus damageZomieA value. The correct way to subtract it, is zombieAHealth-=damageZombieA;
Note that the minus sign is now before the equal sign