Must return a value Error

Can anyone help me about my homework?

I can not compile this code without error it says besle_kontrol() must return a valuei donno what to do ?

Thanks from now
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
 #pragma once

#include<iostream>
#include<conio.h>
#include "stdafx.h"

using namespace std;

class base_evcil_hayvan
{
public:
	int oyun;
	int tokluk;
	base_evcil_hayvan()
	{

	}

	bool besle_kontrol()
	{

	}
};

class kedi : public base_evcil_hayvan
{
public:
	int oyun = 50;
	int tokluk = 50;
	kedi()
	{

	}

	bool besle_kontrol()
	{
		bool onay = true;
		do
		{
			cout << "Kedi [Y]emi\n[K]edi Oyna";
			char secim;
			cin >> secim;

			if (tokluk<50)
			{
				cout << "miyav miyav";
			}
			else
			{
				cout << "miyav";
				switch (secim)
				{
				case 'Y':
					tokluk += 50;
					break;

				case 'K':
					oyun += 50;
					break;

				default: cout << "Hatali Secim : ";
					tokluk += 20;
					oyun += 20;
					break;
				}
				tokluk -= 20;
				oyun -= 20;
			}
			if (onay <= 0 || tokluk <= 0)
			{
				onay = false;
			}
		} while (oyun>0 || tokluk>0);
		return onay;
	}
};

class kopek : public base_evcil_hayvan
{
public:
	int oyun = 50;
	int tokluk = 50;

	kopek()
	{

	}

	bool besle_kontrol()
	{
		bool onay = true;
		do
		{
			cout << "K[o]pek Yem\nKo[p]ek Oyna";
			char secim;
			cin >> secim;

			if (tokluk<50)
			{
				cout << "hav hav";
			}
			else
			{
				cout << "hav";
				switch (secim)
				{
				case 'o':
					tokluk += 50;
					break;

				case 'p':
					oyun += 50;
					break;

				default: cout << "Hatali Secim : ";
					tokluk += 20;
					oyun += 20;
					break;
				}
				tokluk -= 20;
				oyun -= 20;
			}
			if (onay <= 0 || tokluk <= 0)
			{
				onay = false;
			}
		} while (oyun>0 || tokluk>0);
		return onay;
	}
};

class kus : public base_evcil_hayvan
{
public:
	int oyun = 50;
	int tokluk = 50;
	kus()
	{

	}

	bool besle_kontrol()
	{
		bool onay = true;
		do
		{
			cout << "K[u]s Yemi\nKus Oy[n]a";
			char secim;
			cin >> secim;

			if (tokluk<50)
			{
				cout << "cik cik";
			}
			else
			{
				cout << "cik";
				switch (secim)
				{
				case 'u':
					tokluk += 50;
					break;

				case 'n':
					oyun += 50;
					break;

				default: cout << "Hatali Secim : ";
					tokluk += 20;
					oyun += 20; break;
				}
				tokluk -= 20;
				oyun -= 20;
			}
			if (onay <= 0 || tokluk <= 0)
			{
				onay = false;
			}
		} while (oyun>0 || tokluk>0);
		return onay;
	}
};



int main()
{

	int h_sayisi = 0;
	short puan = 0;
	bool onay = true;
	kedi *c = new kedi;
	kopek *d = new kopek;
	kus *b = new kus;

	base_evcil_hayvan *beh[3];

	beh[0] = c;
	beh[1] = d;
	beh[2] = b;

	do
	{
		puan += 10;
		for (int i = 0; i<3; i++)
		{
			onay = beh[i]->besle_kontrol();
			if (onay)
				h_sayisi--;
			beh[i]->besle_kontrol();
		}
	} while (h_sayisi > 0);
	cout << "Puaniniz : " << endl;
	cout << puan;
	system("pause");
	return 0;
}
The return type of besle_kontrol() is bool so you have to return a boolean value (true or false) from that function.
I reviewed my code again and found some wrong parameters than changed them.

But still i couldn't understand where to change the return value
of besle_kontrol() ? in class base_evcil_hayvan or in main scope ?
@peter87 can you show me how to do it ?


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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#pragma once

#include<iostream>
#include<conio.h>
#include "stdafx.h"

using namespace std;

class base_evcil_hayvan
{
public:
	int oyun;
	int tokluk;
	base_evcil_hayvan()
	{

	}

	bool besle_kontrol()
	{

	}
};

class kedi : public base_evcil_hayvan
{
public:
	int oyun = 50;
	int tokluk = 50;
	kedi()
	{

	}

	bool besle_kontrol()
	{
		bool onay = true;
		do
		{
			cout << "Kedi [Y]emi\n[K]edi Oyna";
			char secim;
			cin >> secim;

			if (tokluk<50)
			{
				cout << "miyav miyav";
			}
			else
			{
				cout << "miyav";
				switch (secim)
				{
				case 'Y':
					tokluk += 50;
					break;

				case 'K':
					oyun += 50;
					break;

				default: cout << "Hatali Secim : ";
					tokluk += 20;
					oyun += 20;
					break;
				}
				tokluk -= 20;
				oyun -= 20;
			}
			if (oyun <= 0 || tokluk <= 0)
			{
				onay = false;
			}
		} while (oyun>0 || tokluk>0);
		return onay;
	}
};

class kopek : public base_evcil_hayvan
{
public:
	int oyun = 50;
	int tokluk = 50;

	kopek()
	{

	}

	bool besle_kontrol()
	{
		bool onay = true;
		do
		{
			cout << "K[o]pek Yem\nKo[p]ek Oyna";
			char secim;
			cin >> secim;

			if (tokluk<50)
			{
				cout << "hav hav";
			}
			else
			{
				cout << "hav";
				switch (secim)
				{
				case 'o':
					tokluk += 50;
					break;

				case 'p':
					oyun += 50;
					break;

				default: cout << "Hatali Secim : ";
					tokluk += 20;
					oyun += 20;
					break;
				}
				tokluk -= 20;
				oyun -= 20;
			}
			if (oyun <= 0 || tokluk <= 0)
			{
				onay = false;
			}
		} while (oyun>0 || tokluk>0);
		return onay;
	}
};

class kus : public base_evcil_hayvan
{
public:
	int oyun = 50;
	int tokluk = 50;
	kus()
	{

	}

	bool besle_kontrol()
	{
		bool onay = true;
		do
		{
			cout << "K[u]s Yemi\nKus Oy[n]a";
			char secim;
			cin >> secim;

			if (tokluk<50)
			{
				cout << "cik cik";
			}
			else
			{
				cout << "cik";
				switch (secim)
				{
				case 'u':
					tokluk += 50;
					break;

				case 'n':
					oyun += 50;
					break;

				default: cout << "Hatali Secim : ";
					tokluk += 20;
					oyun += 20; break;
				}
				tokluk -= 20;
				oyun -= 20;
			}
			if (oyun <= 0 || tokluk <= 0)
			{
				onay = false;
			}
		} while (oyun>0 || tokluk>0);
		return onay;
	}
};



int main()
{

	int h_sayisi = 0;
	short puan = 0;
	bool onay = true;
	kedi *c = new kedi;
	kopek *d = new kopek;
	kus *b = new kus;

	base_evcil_hayvan *beh[3];

	beh[0] = c;
	beh[1] = d;
	beh[2] = b;

	do
	{
		puan += 10;
		for (int i = 0; i<3; i++)
		{
			onay = beh[i]->besle_kontrol();
			if (onay)
				h_sayisi--;
			beh[i]->besle_kontrol();
		}
	} while (h_sayisi > 0);
	cout << "Puaniniz : " << endl;
	cout << puan;
	system("pause");
	return 0;
}
line 21
return false;
i gave it a try by writing line 21 to return false; than it compiled without error but it shows only
cout << "Puaniniz : " << endl;
cout << puan;
system("pause");
return 0;
this scoope result at console by skipping all of the code
because h_sayisi starts at 0 and is then decremented.

so the loop at 212 always falls through because h_sayisi is never >0.
I updated code with your suggestions than i can not see naything at console window when i run code.

It should show me menu from derived objects from produced my base class but can not show them to user to make choices


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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#pragma once

#include<iostream>
#include<conio.h>
#include "stdafx.h"

using namespace std;

class base_evcil_hayvan
{
public:
	int oyun;
	int tokluk;
	base_evcil_hayvan()
	{

	}

	bool besle_kontrol()
	{
		return false;
	}
};

class kedi : public base_evcil_hayvan
{
public:
	int oyun = 50;
	int tokluk = 50;
	kedi()
	{

	}

	bool besle_kontrol()
	{
		bool onay = true;
		do
		{
			cout << "Kedi [Y]emi\n[K]edi Oyna";
			char secim;
			cin >> secim;

			if (tokluk<50)
			{
				cout << "miyav miyav";
			}
			else
			{
				cout << "miyav";
				switch (secim)
				{
				case 'Y':
					tokluk += 50;
					break;

				case 'K':
					oyun += 50;
					break;

				default: cout << "Hatali Secim : ";
					tokluk += 20;
					oyun += 20;
					break;
				}
				tokluk -= 20;
				oyun -= 20;
			}
			if (onay <= 0 || tokluk <= 0)
			{
				onay = false;
			}
		} while (oyun>0 || tokluk>0);
		return onay;
	}
};

class kopek : public base_evcil_hayvan
{
public:
	int oyun = 50;
	int tokluk = 50;

	kopek()
	{

	}

	bool besle_kontrol()
	{
		bool onay = true;
		do
		{
			cout << "K[o]pek Yem\nKo[p]ek Oyna";
			char secim;
			cin >> secim;

			if (tokluk<50)
			{
				cout << "hav hav";
			}
			else
			{
				cout << "hav";
				switch (secim)
				{
				case 'o':
					tokluk += 50;
					break;

				case 'p':
					oyun += 50;
					break;

				default: cout << "Hatali Secim : ";
					tokluk += 20;
					oyun += 20;
					break;
				}
				tokluk -= 20;
				oyun -= 20;
			}
			if (onay <= 0 || tokluk <= 0)
			{
				onay = false;
			}
		} while (oyun>0 || tokluk>0);
		return onay;
	}
};

class kus : public base_evcil_hayvan
{
public:
	int oyun = 50;
	int tokluk = 50;
	kus()
	{

	}

	bool besle_kontrol()
	{
		bool onay = true;
		do
		{
			cout << "K[u]s Yemi\nKus Oy[n]a";
			char secim;
			cin >> secim;

			if (tokluk<50)
			{
				cout << "cik cik";
			}
			else
			{
				cout << "cik";
				switch (secim)
				{
				case 'u':
					tokluk += 50;
					break;

				case 'n':
					oyun += 50;
					break;

				default: cout << "Hatali Secim : ";
					tokluk += 20;
					oyun += 20; break;
				}
				tokluk -= 20;
				oyun -= 20;
			}
			if (onay <= 0 || tokluk <= 0)
			{
				onay = false;
			}
		} while (oyun>0 || tokluk>0);
		return onay;
	}
};



int main()
{

	int h_sayisi = 3;
	short puan = 0;
	bool onay = true;
	kedi *c = new kedi;
	kopek *d = new kopek;
	kus *b = new kus;

	base_evcil_hayvan *beh[3];

	beh[0] = c;
	beh[1] = d;
	beh[2] = b;

	do
	{
		puan += 10;
		for (int i = 0; i<3; i++)
		{
			onay = beh[i]->besle_kontrol();
			if (onay)
				h_sayisi--;
			beh[i]->besle_kontrol();
		}
	} while (h_sayisi > 0);
	cout << "Puaniniz : " ;
	cout << puan << endl;
	system("pause");
	return 0;
}
I just created a project with your latest code and it does not compile.

1
2
3
4
5
6
7
8
9
c:\users\jay\documents\visual studio 2010\projects\test123\test123.cpp(33): error C2864: 'kedi::oyun' : only static const integral data members can be initialized within a class
c:\users\jay\documents\visual studio 2010\projects\test123\test123.cpp(34): error C2864: 'kedi::tokluk' : only static const integral data members can be initialized within a class
c:\users\jay\documents\visual studio 2010\projects\test123\test123.cpp(74): warning C4804: '<=' : unsafe use of type 'bool' in operation
c:\users\jay\documents\visual studio 2010\projects\test123\test123.cpp(86): error C2864: 'kopek::oyun' : only static const integral data members can be initialized within a class
c:\users\jay\documents\visual studio 2010\projects\test123\test123.cpp(87): error C2864: 'kopek::tokluk' : only static const integral data members can be initialized within a class
c:\users\jay\documents\visual studio 2010\projects\test123\test123.cpp(128): warning C4804: '<=' : unsafe use of type 'bool' in operation
c:\users\jay\documents\visual studio 2010\projects\test123\test123.cpp(140): error C2864: 'kus::oyun' : only static const integral data members can be initialized within a class
c:\users\jay\documents\visual studio 2010\projects\test123\test123.cpp(141): error C2864: 'kus::tokluk' : only static const integral data members can be initialized within a class
c:\users\jay\documents\visual studio 2010\projects\test123\test123.cpp(180): warning C4804: '<=' : unsafe use of type 'bool' in operation


which compiler are you using?

to clear the errors....
1
2
3
4
5
6
7
8
public:
	int oyun = 50;
	int tokluk = 50;

	kopek()
	{

	}


should look like...
1
2
3
4
5
6
7
8
9
public:
	int oyun;
	int tokluk;

	kopek()
	{
 	   oyun = 50;
   	   tokluk = 50;
	}


apply that to all of your classes.

as for the warnings...

i think
if (onay <= 0 || tokluk <= 0)
should be...
if (oyun <= 0 || tokluk <= 0)
Topic archived. No new replies allowed.