Critter caretaker help

I am new to creating class and this is our assignment:
Change the Critter Caretaker from Chapter 8 (pgs 274-281) program:
Create an unlisted menu option that reveals the exact values of the critter's hunger and boredom levels.
This means you create an option that will be acted on from the menu list - BUT you don't display that option. It's "secret".
Make the critter more expressive about it's needs by hinting at both how hungry and bored it is. "I'm starving!", "I'm hungry", "I'm full", etc. The user should have to do nothing for the critter to express it's needs. In other words, this should not happen in response to a menu item being selected, or only when one menu item is selected.

This is the original 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
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
//Critter Caretaker
//Simulates caring for a virtual pet

#include <iostream>

using namespace std;

class Critter
{
public:          
    Critter(int hunger = 0, int boredom = 0); 
    void Talk();
    void Eat(int food = 4);
    void Play(int fun = 4);

private:
    int m_Hunger;
    int m_Boredom;

    int GetMood() const;
    void PassTime(int time = 1);

};

Critter::Critter(int hunger, int boredom):
    m_Hunger(hunger),
    m_Boredom(boredom)
{}

inline int Critter::GetMood() const 
{
    return (m_Hunger + m_Boredom);
}

void Critter::PassTime(int time)
{
    m_Hunger += time;
    m_Boredom += time;
}

void Critter::Talk()
{
    cout << "I'm a critter and I feel ";

    int mood = GetMood();
    if (mood > 15)
	{
        cout << "mad.\n";
	}
    else if (mood > 10)
	{
        cout << "frustrated.\n";
	}
    else if (mood > 5)
	{
        cout << "okay.\n";
	}
    else
	{
        cout << "happy.\n";
	}

    PassTime();
}

void Critter::Eat(int food) 
{
    cout << "Brruppp.\n";

    m_Hunger -= food;
    if (m_Hunger < 0)
	{
        m_Hunger = 0;
	}

    PassTime();
}

void Critter::Play(int fun)
{
    cout << "Wheee!\n";

    m_Boredom -= fun;
    if (m_Boredom < 0)
	{
        m_Boredom = 0;
	}

    PassTime();
}

int main()
{
    Critter crit;

    int choice = 1;  //start the critter off talking
    while (choice != 0)
    {
        cout << "\nCritter Caretaker\n\n";
        cout << "0 - Quit\n";
        cout << "1 - Listen to your critter\n";
        cout << "2 - Feed your critter\n";
        cout << "3 - Play with your critter\n\n";

        cout << "Choice: ";
        cin >> choice;

        switch (choice)
        {
        case 0:	
            cout << "Good-bye.\n";
			break;
        case 1:	
            crit.Talk();
			break;
        case 2:	
            crit.Eat();
			break;
        case 3:	
            crit.Play();
			break;
        default:
            cout << "\nSorry, but " << choice << " isn't a valid choice.\n";
        }
    }

    return 0;
}


Here is what i changed it to:
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
//Critter Caretaker
//Simulates caring for a virtual pet


#include <iostream>

using namespace std;

class Critter
{
public:          
    Critter(int hunger = 0, int boredom = 0); 
    void Talk();
    void Eat(int food = 4);
    void Play(int fun = 4);
	void ShowHungerBoredum(); //function to show hunger and boredum levels

private:
    int m_Hunger;
    int m_Boredom;

    int GetMood() const;
    void PassTime(int time = 1);

};

Critter::Critter(int hunger, int boredom):
    m_Hunger(hunger),
    m_Boredom(boredom)
{}

inline int Critter::GetMood() const 
{
    return (m_Hunger + m_Boredom);
}

void Critter::PassTime(int time)
{
    m_Hunger += time;
    m_Boredom += time;
}

void Critter::Talk()
{
    cout << "I'm a critter and I feel ";

    int mood = GetMood();
    if (mood > 15)
	{
        cout << "mad.\n";
	}
    else if (mood > 10)
	{
        cout << "frustrated.\n";
	}
    else if (mood > 5)
	{
        cout << "okay.\n";
	}
    else
	{
        cout << "happy.\n";
	}
	ShowHungerBoredum();
    PassTime();
}

void Critter::Eat(int food) 
{
    cout << "Brruppp.\n";
	

    m_Hunger -= food;
    if (m_Hunger < 0)
	{
        m_Hunger = 0;
	}
	ShowHungerBoredum();
    PassTime();
}

void Critter::Play(int fun)
{
    cout << "Wheee!\n";
	
    m_Boredom -= fun;
    if (m_Boredom < 0)
	{
        m_Boredom = 0;
	}
	ShowHungerBoredum();
    PassTime();
}

void Critter::ShowHungerBoredum()
{
	if ((m_Hunger <= 4) && (m_Boredom <= 4))
	{
		cout << "I'm full and but i'm not bored. \n";
	}
	else if ((m_Hunger <= 4) && ((m_Boredom > 3 && m_Boredom <= 10)))
	{
		cout << "I'm full, but i'm kinda bored.\n";
	}
	else if ((m_Hunger <= 4) && (m_Boredom >= 10))
	{
		cout << "I'm full, but i'm very bored. \n";
	}
	else if ((m_Boredom <= 4) && ((m_Hunger > 4 && m_Hunger < 10)))
	{
		cout << "I'm kinda hungry, but i'm not bored. \n";
	}
	else if (((m_Boredom > 4 && m_Boredom < 10)) && ((m_Hunger > 4 && m_Hunger < 10)))
	{
		cout << "I'm kinda hungry and i'm kinda bored. \n";
	}
	else if ((m_Boredom >= 10) && ((m_Hunger > 4 && m_Hunger < 10)))
	{
		cout << "I'm kinda hungry, but i'm very bored. \n";
	}
	else if ((m_Hunger >= 10) && (m_Boredom <= 4))
	{
		cout << "I'm starving, but i'm not bored. \n";
	}
	else if ((m_Hunger >= 10) && ((m_Boredom > 4 && m_Boredom < 10)))
	{
		cout << "I'm starving, and i'm kinda bored. \n";
	}
	else if ((m_Hunger >= 10) && (m_Boredom >= 10))
	{
		cout << "I'm starving, and i'm very bored! \n";
	}
}
int main()
{
    Critter crit;

    int choice = 1;  //start the critter off talking
    while (choice != 0)
    {
        cout << "\nCritter Caretaker\n\n";
        cout << "0 - Quit\n";
        cout << "1 - Listen to your critter\n";
        cout << "2 - Feed your critter\n";
        cout << "3 - Play with your critter\n\n";

        cout << "Choice: ";
        cin >> choice;

        switch (choice)
        {
        case 0:	
            cout << "Good-bye.\n";
			break;
        case 1:	
            crit.Talk();
			break;
        case 2:	
            crit.Eat();
			break;
        case 3:	
            crit.Play();
			break;
		case 4: //secret menu option that displays exact hunger and boredum levels
			cout << "\nCritter Hunger Level: " << m_Hunger << ".\n";
			cout << "\nCritter Boredum Level: " << m_Boredom << ".\n";
		default:
            cout << "\nSorry, but " << choice << " isn't a valid choice.\n";
        }
    }

    return 0;
}


The problem im having is that it is saying that identifier m_Hunger and identifier m_Boredum are undefined Here:
1
2
3
4
		
case 4: //secret menu option that displays exact hunger and boredum levels
			cout << "\nCritter Hunger Level: " << m_Hunger << ".\n";
			cout << "\nCritter Boredum Level: " << m_Boredom << ".\n";

above here:
1
2
3
4
5
6
7
8
private:
    int m_Hunger;
    int m_Boredom;

    int GetMood() const;
    void PassTime(int time = 1);

};

i thought they were defined so i tried changing private to public and that didnt help. Im lost and could use at least a nudge in the right direction if not an explanation of what im doing wrong. Thanks.
figured it out. I had to make a separate function outside of main but inside the class for case 4 then call it on case 4
1
2
3
4
5
6
7
public:          
    Critter(int hunger = 0, int boredom = 0); 
    void Talk();
    void Eat(int food = 4);
    void Play(int fun = 4);
	void ShowHungerBoredum(); //function for critter to be more expressive
	void DisplayLevels(); // function for displaying hunger and boredum levels 


1
2
3
4
5
void Critter::DisplayLevels()
{
	cout << "\nCritter Hunger Level: " << m_Hunger << ".\n";
	cout << "\nCritter Boredum Level: " << m_Boredom << ".\n";
}


1
2
3
case 4: //secret menu option that displays exact hunger and boredum levels
			crit.DisplayLevels();
			break;
As they are private variables in the class, you need public getters (and setters) to access the private data values. You cannot access them directly. You need to change to something like this
1
2
3
4
5
void Critter::DisplayLevels()
{
	cout << "\nCritter Hunger Level: " << getHunger() << ".\n";
	cout << "\nCritter Boredum Level: " <<getBoredom() << ".\n";
}
Topic archived. No new replies allowed.