Text-Based RPG bug. Please Help!

Hey everyone. I'm not exactly new to programming, but I haven't programmed very much in a while, and the last time I did, the best thing I could make was a pong clone. This time I am trying to make a console text-based RPG. After a while I came across a bug and it's been hours and I still can't figure out how to fix it.
The bug is during the battle, when you hit the enemy, it doesn't register the damage in the function that keeps a loop of the battle going. This is a big problem because without it registering the damage, the battle will never end.
Here is some of the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  int heroAttack(Enemy enemy)
{
    int damage = 0;
    int hitRate = rand() % 5 + rand() % mainHero.mainClass.strength;
    cout << hitRate;
    if(hitRate >= enemy.AC)
    {
        damage = rand() % mainHero.mainClass.strength + mainHero.level;
        cout << damage;
        typePrint("Hit!\n");
    }
    return damage;
}

void battleStart(Enemy enemy)
{
    typePrint(enemy.enemyDscpn + "\n");
    typePrint("Your enemy is: " + enemy.enemyName + "\n");
    typePrint("Type: " + enemy.enemyClass.classType + "\n");
    enemy.showHealth();

}

void playerTurn(Enemy enemy)
{
    int choice = 0;
    string choiceLetter;
    while(choice == 0)
    {
        typePrint("It's your turn! \n (A to attack, B to block, or S to see your basic stats (which does not take up your turn)) \n ");
        cin >> choiceLetter;
        if(choiceLetter == "A")
        {
            enemy.currentHealth -= heroAttack(enemy);

            choice = 1;
        }
        else if(choiceLetter == "B")
        {
            choice = 2;
        }
        else if(choiceLetter == "S")
        {
            mainHero.showBasicStats();
        }
        else
        {
            typePrint("That is not a valid choice.\n");
        }
    }

}

void enemyTurn(Enemy enemy)
{

}

void battle(Enemy enemy)
{
    int winCondition = 0;
    battleStart(enemy);


    while(winCondition == 0)
    {


        if(enemy.currentHealth == 0)
        {
            winCondition = 1;

        }
        else if(mainHero.currentHealth == 0)
        {
            winCondition = 2;
        }
        else
        {
            playerTurn(enemy);
            enemy.showHealth();
        }



        if(enemy.currentHealth == 0)
        {
            winCondition = 1;
        }
        else if(mainHero.currentHealth == 0)
        {
            winCondition = 2;
        }
        else
        {
            enemyTurn(enemy);
        }

    }
    
}
int heroAttack(Enemy enemy)

These functions are not modifying the enemy you are passing in; they are making a copy and modifying the copy, which is then destroyed when the function ends. Look up passing parameters by reference.
Wow, thank you so much firedraco! that worked perfectly!
Topic archived. No new replies allowed.