I'm programming this RPG, and I can't get past the first battle. I can't figure out how to get the computer to break the loop when then enemy's health (enhp) is less than 1. I tried using an if statement, but then it didn't loop at all. Could you guys help me out?
#include <iostream>
#include <string>
using namespace std;
int main (void)
{
int num, random_integer, hp= 100, enhp= 50;
while (hp >=1 or enhp >=1)
{
{srand((unsigned)time(0));
for(int index=0; index<20; index++)
{random_integer = (rand()%10)+1;
hp = hp-random_integer;
if (hp>=1)
{cout<<"The enemy does "<<random_integer<<" damage, leaving you with "<<hp<<" health.";
cout<<"\n1)Attack!\n 2)I've had enough- run away!";
cin>>num;}
if(num ==1)
{srand((unsigned)time(0));
for(int index=0; index<20; index++)
{random_integer = (rand()%10)+1;}
enhp = enhp-random_integer;
cout<<"You have done "<<random_integer<<" damage." ;}
else
cout<<"You have fled";
}
system("PAUSE");
return 0;
}
}
}