So I tried to make a little text-based battle system, but it kind of broke... I was wondering if someone could help me figure out why? I tried to use variables and simple math algorithms to make it as easy to run as possible, but it just keeps resetting after player 2's turn. It also broadcasts the "You Can't Heal!" (player 2's turn) message even if the player doesn't heal. I checked the brackets a couple times, as well as my de-bugger, however it says that everything is fine. I'm not sure what the problem is, so if someone could point it out that would be great. Thanks in advance!
Code Below V
using namespace std
int varset()
{
string ChoiceTeamA;
string ChoiceTeamB;
bool Atk1 = false;
bool Atk2 = false;
int health = health;
int health1 = health1;
}
int main() {
cout << "player 1 turn - choose what to do" << endl;
cout << "Player 1's health is " << health << " and Player 2's health is " << health1 << endl;
cout << "A. Attack" << endl;
cout << "B. Heal Magic" << endl;
getline(cin, ChoiceTeamA);
if (ChoiceTeamA == "A")
{
string ChoiceTeamA = "c";
health1--;
bool Atk1 = false;
cout << "Player 1 attacked! Player 2's health is now " << health1 << endl;
}
if (ChoiceTeamA == "B")
{
string ChoiceTeamA = "0";
if (health < 5)
{
health++;
cout << "Player 1 healed! Player 1's health is now " << health;
}
else
{
cout << "You can't heal!" << endl;
}
}
cout << "." << endl;
cout << "player 2 turn - choose what to do" << endl;
cout << "Player 1's health is " << health << " and Player 2's health is " << health1 << endl;
cout << "A. Attack" << endl;
cout << "B. Heal Magic" << endl;
getline(cin, ChoiceTeamB);
if (ChoiceTeamB == "A")
string ChoiceTeamB = "c";
{
string ChoiceTeamA = "c";
health--;
bool Atk2 = false;
cout << "Player 2 attacked! Player 1's health is now " << health << endl;
}
if (ChoiceTeamB == "B")
{
string ChoiceTeamA = "c";
if (health < 5)
{
health1++;
cout << "Player 2 healed! Player 2's health is now " << health1;
}
if (health = 5)
{
cout << "You can't heal!" << endl;
cout << "." << endl;
}
}
if (health = 0)
{
cout << "Player 2 wins!!!";
return 0;
}
if (health1 = 0)
{
cout << "Player 1 wins!!!";
return 0;
}
return main();
}