Jan 8, 2015 at 1:26am UTC
here's my code sorry the box kinda cuts it off and puts it on the next line, but my problem is that in this do while looop the whenever the alien health or user health gets to zero the loop doesn't stop and the health will go into the negatives
do
{
int attackingchoice;
system("CLS");
cout << "Your Health: " << health_B << " Alien Health: " << alien_health << endl;
cout << "\n";
cout << "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» " << endl;
cout << "º What would you like to do º" << endl;
cout << "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹" << endl;
cout << "º 1) Attack º" << endl;
cout << "º 2) Retreat º" << endl;
cout << "º º" << endl;
cout << "º º" << endl;
cout << "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n" << endl;
cout << "What would you like to do: ";
cin >> attackingchoice;
cout << "\n\n";
switch (attackingchoice)
{
case 1:
{
int bonus = time(0);
int bonusx = (bonus % 25) + 1;
int attack = CannonSlots * EquippedCS;
int alien_Damage = ((level * 2) * 10) + bonusx;
cout << "You shoot all your cannons at the Alien. " << endl;
Sleep(600);
cout << "You deal " << attack << " damage to the alien. " << endl;
alien_health = alien_health - attack;
Sleep(600);
cout << "\n";
if (alien_health <= 0)
{
}
break;
}
case 2:
{
int running = time(0);
int run = (running % 100) + 1;
cout << "Running... \n\n";
Sleep(600);
if (run <= 50)
{
health_B = 0;
alien_health = 0;
}
else
{
cout << "You weren't able to run away... " << endl;
Sleep(600);
}
break;
}
}
} while (health_B > 0 || alien_health > 0);
system("pause");
Jan 8, 2015 at 5:33am UTC
the loop is executed if health_B>0 OR alien_health>0. So the loop executes unless BOTH are negative or 0. I assume that you wanted AND instead. && instead of ||