Hi, im learning c++ currently and am adventuring into creating a very basic game, I posted list week regarding a problem with a while loop on a coin flip program, I currently have an issue with the following code and was hoping someone could offer me advice. (please ignore the int startfight2 and my over-indulgent use of header files).
#include <string>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
using namespace std;
int userhitpoints = 100;
int manhitpoints = 100;
int bla;
int startfight;
int startfight2;
int main()
{
cout << "Begin?\n\n1: Yes\n2:No\n\n";
cin >> startfight;
if (startfight == 1)
{
cout << "\nA man approaches you 'lets fight'\n\n1:Fight\n2:Defend\n\n";
cin >> startfight2;
if (startfight2 == 1)
{
do
{
srand(time(0));
int damage = rand() % (50 - 10) + 10;
int damage2 = rand() % (50 - 10) + 10;
int minushp = userhitpoints - damage;
cout << "\nYou hit the man for: " << damage << "\nThe man hits you for: " << damage2 << "\n\n" << "mans Hit Points:" << minushp;
cout << "\nYour Hit Points: ";
int minushp2 = manhitpoints - damage2;
cout << minushp2 << "\n\nHit Again?\n";
cin >> startfight2;
}
while (manhitpoints > 0);
}
else
{
cout << "You are dead";
}
}
else if (startfight2 == 2)
{
int damage = rand() % (50 - 10) + 10;
int defend = damage / 2;
cout << "You defend and do 0 damage";
}
else
cout << "fail";
return 0;
}
Its a work in progress and isn't complete but my current issue regards the "hitpoints" integers i want them to retain their value after the first loop so the attacker will have to keep attacking untill either userhitpoints or manhitpoints reaches 0.