critter is dead

i tired what i know still couldn't figure out , i have to modify the program if the critter is dead can't do anything. i did a little modification in the talk when u knw the critter is dead and i add static const int MAX_Hunger = 15;, bool m_IsAlive; idk how to use this i tried but didn't work. also i don't understand the use of "bool"

pls help.
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
//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);
     static const int MAX_Hunger = 15;
private:
    int m_Hunger;
    int m_Boredom;
   
    int GetMood() const;
    void PassTime(int time = 1);
     bool m_IsAlive;
};

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 << "dead.\n";
         
    else if (mood > 10)
        cout << "frustrated.\n";
       
    else if (mood > 5)
        cout << "okay.\n";
    else
        cout << "happy.\n";
   
        if (m_Hunger <= 0)
cout << "I'm not hungry\n";
else if (m_Hunger < 5)
cout << "I'm slightly hungry\n";
else if (m_Hunger < 10)
cout << "I'm hungry\n";
else if (m_Hunger <15)
cout << "died fom hungry\n";


  
    PassTime();
}

void Critter::Eat(int food) 
{
    cout << "Brruppp.\n";
    m_Hunger -= food;
    if (m_Hunger < 0)
        m_Hunger = 0;
    PassTime();
     MAX_Hunger();
}

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;
}
Um, what? This feels like coming in at the end of a conversation. Did you accidentally delete some of your explanatory text?

To answer your final comment - bool is a type that can only take one of two values: true and false.
Last edited on
Well here's a simple way to test if the Critter is still alive or dead, if it's dead then the program will display 'Game Over' and exit.


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
#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 getcurrentstats();
private:
	bool DeadorAlive;
	int m_Hunger;
	int m_Boredom;
	void passtime (int time = 1);
	int getmood() const;
};
void Critter::getcurrentstats()
{
	cout<<"My hunger level is " <<m_Hunger;
	cout<<"\nand my boredom level is " <<m_Boredom<<endl;
	if ( m_Hunger > 15 && m_Boredom > 15 )
	{
		DeadorAlive = true;
	}
	if ( DeadorAlive == true )
	{
		cout<<"You have failed to take care of your Critter.\n";
		cout<<"Game over"<<endl;
		exit(0);
	}
}
Critter::Critter(int hunger, int boredom):
	m_Hunger(hunger) , m_Boredom(boredom)
{
}
int Critter::getmood() const
{
	return (m_Hunger + m_Boredom);
}
void Critter::passtime(int time)
{
	m_Hunger += time;
	m_Boredom += time;
}
void Critter::talk()
{
	cout<<"Hi! I'm a Critter and i'm feeling ";
	int mood = getmood();
	if ( mood > 15 )
	{
		cout<<"Mad!\n";
	}
	if ( mood > 10 )
	{
		cout<<"Frustrated\n";
	}
	if ( mood > 5 )
	{
		cout<<"okay\n";
	}
	else
	{
		cout<<"Happy!\n";
	}
	passtime();
	if ( m_Hunger > 15 && m_Boredom > 15 )
	{
		DeadorAlive = true;
	}
	if ( DeadorAlive == true )
	{
		cout<<"You have failed to take care of your Critter.\n";
		cout<<"Game over"<<endl;
		exit(0);
	}
}
void Critter::eat(int hunger)
{
	cout<<"Num num num\n";
	m_Hunger -= hunger;
	if ( m_Hunger < 0 )
	{
		m_Hunger = 0;
	}
	passtime();
	if ( m_Hunger > 15 && m_Boredom > 15 )
	{
		DeadorAlive = true;
	}
	if ( DeadorAlive == true )
	{
		cout<<"You have failed to take care of your Critter.\n";
		cout<<"Game over"<<endl;
		exit(0);
	}
}
void Critter::play(int fun)
{
	cout<<"Wheeeeee\n";
	m_Boredom -= fun;
	if ( m_Boredom < 0 )
	{
		m_Boredom = 0;
	}
	passtime();
	if ( m_Hunger > 15 && m_Boredom > 15 )
	{
		DeadorAlive = true;
	}
	if ( DeadorAlive == true )
	{
		cout<<"You have failed to take care of your Critter.\n";
		cout<<"Game over"<<endl;
		exit(0);
	}
}
int main()
{
	Critter Crit;
	Crit.talk();
	cout<<"\nCritter Caretaker";
	cout<<"\n-----------------\n\n";
	int choice;
	do
	{
		cout<<"0 - Quit\n";
		cout<<"1 - Listen to your Critter\n";
		cout<<"2 - Feed your Critter\n";
		cout<<"3 - Play with your Critter\n";
		cout<<"4 - Show Critter's current stats\n";

		cout<<"\nChoice: ";
		cin>>choice;
		switch (choice)
		{
		case 0:
			cout<<"Thank you for playing\n";
			break;
		case 1:
			Crit.talk();
			break;
		case 2:
			Crit.eat();
			break;
		case 3:
			Crit.play();
			break;
		case 4:
			Crit.getcurrentstats();
			break;
		default:
			cout<<"Illegal choice, please try again.\n";
		}
		
	}while ( choice != 0 );
	return 0;
}
Last edited on
Topic archived. No new replies allowed.