Do damage help

In my classes, my damage script does not work. I think it might be because classes cant access other classes? I dont know, my book only had a 2 chapters over classes. I do these daily programs I make up just to help me out later on. There are two things I need help with.

1) How to get the damage() and hurt() functions to work.
2) Is there a way to make it one answer for the if(answer == "Yes" || answer == "yes" || answer == "YES")? I tried using toupper(), but it didnt work. (My book only mentioned what toupper did, not how to use it). This is how i used it: answer = (string)toupper();.
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;



class Player
{
    int health = 100;
    int Energ = 100;
public:
    int GetHealth();
    void damage(const int&  x);
    int GetEnergy();
private:
    int pHealth = health;
    int Energy = Energ;
};

int Player::GetHealth()
{
    return pHealth;
}

void Player::damage(const int&  x)
{
    srand(time(0));
    int num = x;
    int y = rand()%20;
    num = num - y;
    Energy = Energy - 10;
}

int Player::GetEnergy()
{
return Energy;
}

class Enemy
{
    int heal = 100;
public:
    void hurt(const int& y);
    int GetHeal();
private:
    int eHeal = heal;
};

    void Enemy::hurt(const int& y)
    {
        srand(time(0));
        int r = y;
        int d = rand()%20;
        r = r - d;
    }

    int Enemy::GetHeal()
    {
        return eHeal;
    }

int main()
{
    Player Ron;
    Enemy Obama;
    int x = Obama.GetHeal();
    int R = Ron.GetHealth();
    cout << "\t\t\t\tTesting\n\n";

    string answer;
    do
    {
        cout << "\nYour Health is " << Ron.GetHealth() << ", and your Energy is " << Ron.GetEnergy();
        cout << "\nObama's health is " << Obama.GetHeal();
        cout << "\n\nWhat would you like to do? 1] Attack. 2] Run. 3] Surrender\n";
        cin >> answer;
        if(answer == "1")
        {
            if(Ron.GetEnergy()<=0)
            {
cout << "\n\nYou ran out of energy, and have been killed by Obama\n\n";
break;
            }
            string answer2;
            cout << "\n\nAre you sure you want to attack?\n";
            cin >> answer2;
            if(answer2 == "Yes" || answer2 == "yes" || answer2 == "YES")
            {
                Ron.damage(x);
                cout << "\nYou attacked Obama.\n";
            }
            else if(answer2 == "No" || answer2 == "NO" || answer2 == "no")
            {
            }
            else
            {
                cout << "\nThat was not a valid option\n";
            }
        }
        if(answer == "2")
        {
            string answer3;
            cout << "\n\nAre you sure you want to run?\n";
            cin >> answer3;
             if(answer3 == "Yes" || answer3 == "yes" || answer3 == "YES")
            {
                if(Ron.GetHealth() > Obama.GetHeal())
                {
                    cout << "\n\nYou've ran away successfully!\n\n";
                    cout << "The End\n\n";
                    break;
                }
                else if(Ron.GetHealth() == Obama.GetHeal())
                {
                    int luck;
                    luck = 1+rand()%2;
                    if(luck == 1);
                    {
                        cout << "\nYou escaped!\n";
                        cout << "\nThe End\n\n";
                        break;
                    }
                    if(luck == 2)
                    {
                        cout << "\Obama caught you.\nTheEnd?\n\n";
                        break;
                    }
                }
                else if(Ron.GetHealth() < Obama.GetHeal())
                {
                    cout << "\Obama caught you.\nTheEnd?\n\n";
                        break;
                }
                else
                {
                    cout << "\n\nObama hacked the game?\n";
                }
            }
            else if(answer3 == "No" || answer3 == "NO" || answer3 == "no")
            {
            }
            else
            {
                cout << "\nThat was not a valid option\n";
            }
        }
        if(answer == "3")
        {
             string answer4;
            cout << "\n\nAre you sure you want to Surrender?\n";
            cin >> answer4;
            if(answer4 == "Yes" || answer4 == "yes" || answer4 == "YES")
            {
                cout << "Obama captured you\n";
                break;
            }
            else if(answer4 == "No" || answer4 == "NO" || answer4 == "no")
            {
            }
            else
            {
                cout << "\nThat was not a valid option\n";
            }
        }
        Obama.hurt(R);
    }while(x>0);

    if(Obama.GetHeal()<=0)
    {
        cout << "\n\nYou killed Obama!\n\nYou Won!\n\n";
    }
    else
    {
        cout << "\nThanks for playing!";
    }
}


Thanks, and if you find something that I shouldnt do in my program, please let me know. I'm trying really hard to become a good programmer in the future.
Topic archived. No new replies allowed.