hey guys im just trying to get the function for fighting set up a very basic set up with random numbers, the loop works. but when the number goes down below 0 it starts over i dont understand why or how i can fix this :-/
Code:
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <stdlib.h>
using namespace std;
int fight();
int main()
{
fight();
system("pause");
return 0;
}
int fight()
{
int damage, maxdamage = 18;
int hisdamage, hismax = 5;
int health = 40, hishealth = 20;
srand((unsigned)time(0));
while(hishealth>=0 && health>=0 )
{
damage = (rand()%maxdamage)+1;
cout <<"You have done "<< damage << " damage. "<< endl;
result=hishealth-damage;
cout<<"monster has "<< hishealth <<" hitpoints left." << endl;
hisdamage = (rand()%hismax)+1;
cout<<"Monster did " << hisdamage << " damage to you!"<< endl;
health - hisdamage;
cout<<"You have "<< health <<" hitpoints left." << endl;
}
if(hishealth<=0)
{
cout<<"You have successfully slain the monster.";
}
else if(health<=0)
{
cout<<"you were slain by the monster, game over";
}
}