cannot convert parameter 1 from status to status&

Hi;
I have to use a enum so I can practice what we just learned in class.I keep getting a error. I want to show you my code. I don't know where to put the enum to define it I just tacked it at the top.

I get this error
cannot convert parameter 1 from status to status&
The enum is supposed to be WIN LOSE CONTINUE and the game is supposed to keep going while the selection is continue. I don't really know what to do with the win an lose thing. It seems to make more sense to me to just use a counter after a condition for winning.
Any ideas?

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
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

ifstream fin;
enum status{CONTINUE,WON,LOST};
	
// Display name and game
void DisplaynameAndGame()
{
	cout << "Word Guessing game by Jordan " << endl;
	


}

// Get word from file
string GetWord(string& str1)
{
	fin >> str1;
	return str1;

}

//Messages for first iteration
void firstIteration(string str1, string secret)
{
	
		{ 
			cout << "Starting new game " << endl;
			cout << "My word has " << str1.length() << " characters." << endl;
			cout << "User word is " << secret << endl;
	
		}


}

//Selection for word guess
void guessTheword(string str1, int chances, string& rightword)
{	
	
	int win=1;
	char yesno=' ';
	
	if(chances <6 || yesno =='Y')
	{
	cout << "Do you want to guess the word ,'Y' or 'N' ? " ;
	
	
	cin >> yesno;
	
	switch (yesno)
	{  
		case 'Y':
		cout << "Enter your word now: " ;
		
		cin >> rightword;
		
		if( rightword == str1)
		{
		cout << "Congratulations " << endl;
		if(win==1)
		cout << "You have won " << win << " game. " << endl;
		else if(win>1)
		cout << "You have won " << win << " games. " << endl;
		win++;
		}
		else if(rightword !=str1)
		cout << "Sorry, that is not the word " << endl;
		break;
		
		case 'N': break;
	
		default : if (yesno != 'Y' || yesno!='N')
		cout << "Invalid choice." << endl;
			
	}
		
	}




}

// To display the the matching process
void matchingoutputs( bool match, int& chances, string secret, 
	char letter, string str1, string& rightword)
{
	if(rightword!=str1)
	{
		if(match)
		{
			cout << "The word is now " << secret << 
			'\n' << endl;
			if(chances<7)
			guessTheword(str1, chances, rightword);
		
		
		
		}
		else if(!match)
		{
			cout << "Sorry, no occurrences of " << letter << 
			'\n' << endl;
			if(chances<7)
			guessTheword(str1, chances, rightword);
			chances++;
		}


	}	




}

// Hangman function
void PlayHangman(const string str1)
{	
	
	string rightword ="";
	char choice = ' ';
	char letter=' ';
	string secret (str1.size(), '*' );
	bool match;
	int chances= 0;
	
	// First Iteration message	
	firstIteration(str1, secret);
	
	
		
	
	while(chances !=7)
	{
		match = false;  
		
		
		// User prompt
		if(str1!= rightword)
		{
		cout << "Enter a letter: " ; 
		cin >> letter;  
		}

		// Loop to match letters

		for( string::size_type i=0; i < str1.size(); i++)
		{
			if(str1.at(i) == letter)
			{
			secret.at(i) = letter;
			match = true;
			}
		
		}
		
		matchingoutputs(match,chances,secret, letter, str1, rightword);
		
	}
	
	


}

//For indirect enumeration input/output
void ForEnum(status& CONTINUE, status& WON, status& LOST)
{
	char C = 'C';
	char W = 'W';
	char L = 'L';

	



}
 


void main()

{	
	// Variables
	int wincount=0;
	int coded= 0;
	string str1 = "";
	string star ="*";
	fin.open("input.txt");
	
	
	
	//Main functions
	
		DisplaynameAndGame();
		GetWord(str1);
		PlayHangman(str1);
	    ForEnum(CONTINUE,WON,LOST);
	
	 
	
system("pause");

}



The enum function and the other one that is open because that is where a win message is you will see a counter in that function. And Please just pretend the main says int main() and returns 0;
Thanks
THANKS
Last edited on
And Please just pretend the main says int main() and returns 0;

THIS IS MADNESS. Why don't you just change it? :P

Looks like the error is coming from line 204.
You call function ForEnum which expects three references, and you're giving it constants. Since constants cannot be changed, (non-const) references to them cannot exist.

enums are basically glorified integers, and their possible values (in this case, CONTINUE, WON and LOST) are just constants.

What is ForEnum supposed to do? It seems that you are not using enums correctly.

It's not clear to me what your directions for using the enum are, so I can't help much with that.

By the way, you have some redundancies in your code. On line 77 (the default case of the switch statement), you check if yesno is 'Y' or 'N', which is redundant. The default case is only run when all other cases are not met (assuming you used break correctly). Also, throughout the code, you make redundant checks in if statements. This is redundant:
1
2
3
4
if(x)
    { ... }
else if(!x) // <-- If execution reaches this 'else', it means that 'x' false. So checking if 'x' is false again is unnecessary.
    { ... }


Sorry I couldn't be of more help.
Also, the normal convention is to declare the function before main, then put the definitions after main. This is so we don't have to scroll all the way down to see what main does.

system("pause");

This is also bad - read this article:

http://www.cplusplus.com/forum/articles/11153/
Where are the redundant if's I went through the code and changed the default. I haven't finished the enum function I should of said so. I have to use it for the status of my hangman game. The directions said that if the game status is continue have a loop which keep the game going. So the enum is supposed to be CONTINUE WON LOST. I don't know how to use the enums is correct. I know I cannot input and out directly but I don't know to tie them into this program..


HELP PLEASE!
Where are the redundant if's

Lines 65 and 67, 62 and 71, 95 and 105.
(not sure if you're sayting you changed those or not)

Line 8 declares an enum type of status. Think of enums as a type which contains names for values.
You still need to define an instance of the enum somewhere to hold a value.
e.g. at line 189:
status Status;
Now, you need to set Status to one of the three values.

You might want to change your PlayHangman function to return status;
status PlayHangman(const string str1)

Then in PlayHangman you simply return WON, LOST or CONTINUE.
e.g.
return WON;

In main, you want to check the result of PlayHangman.

Hint: enums work very nicely in switch statements.
1
2
3
4
5
  switch(Status)
  { case WON:  //  do something
                       break;
   ... etc
  }







Thanks for the previous advice. I have tried to make this happen with not very much progress. The program in hangman function doesn't seem to return the WON enum. There is a comment by it. Also I cannot figure out how to output a message asking if they want to continue to play the game. And then using a selection process like
Hint: enums work very nicely in switch statements.

switch(Status)
{ case WON: // do something
break;
... etc
}
As suggested above. I'm just having a hard time drawing this together and getting the program to reiterate if the enum is CONTINUE. Here is what I have. Attemped I drew a blank in main so the selection thing under the comments is not done so hot. This is turned to be the most difficult part for me.
Thanks.

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
218
219
220
221
222
223
224
225
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

ifstream fin;
enum gameEnum{CONTINUE,WON,LOST} status;
	
// Display name and game
void DisplaynameAndGame()
{
	cout << "Word Guessing game by Jordan " << endl;
	


}

// Get word from file
string GetWord(string& str1)  
{	
	fin >> str1;
	
	
	
	
	
	return str1;

}

//Messages for first iteration
void firstIteration(string str1, string secret)
{
	
		{ 
			cout << "Starting new game " << endl;
			cout << "My word has " << str1.length() << " characters." << endl;
			cout << "User word is " << secret << endl;
	
		}


}

//Selection for word guess
void guessTheword(string str1, int chances, string& rightword)
{	
	
	int win=1;
	char yesno=' ';
	
	if(chances <6 )																   //|| yesno =='Y')
	{
	cout << "Do you want to guess the word ,'Y' or 'N' ? " ;
	
	
	cin >> yesno;
	
	switch (yesno)
	{  
		case 'Y':
		cout << "Enter your word now: " ;
		
		cin >> rightword;
		
		if( rightword == str1)
		{
		cout << "Congratulations " << endl;
		if(win==1)
		cout << "You have won " << win << " game. " << endl;
		else if(win>1)
		cout << "You have won " << win << " games. " << endl;
		win++;
		}
		else if(rightword !=str1)
		cout << "Sorry, that is not the word " << endl;
		break;
		
		case 'N': break;
	
		default : 
		cout << "Invalid choice." << endl;
			
	}
		
	}





}

// To display the the matching process
void matchingoutputs( bool match, int& chances, string secret, 
	char letter, string str1, string& rightword)
{
	if(rightword!=str1)
	{
		if(match)
		{
			cout << "The word is now " << secret << 
			'\n' << endl;
			
			guessTheword(str1, chances, rightword);
		
		
		
		}
		else if(!match)
		{
			cout << "Sorry, no occurrences of " << letter << 
			'\n' << endl;
			
			guessTheword(str1, chances, rightword);
			chances++;
		}


	}	

	

}

// Hangman function
gameEnum PlayHangman(const string str1)
{	
	
	string rightword ="";
	char choice = ' ';
	char letter=' ';
	string secret (str1.size(), '*' );
	bool match;
	int chances= 0;
	
	
	
	// First Iteration message	
	firstIteration(str1, secret);
	
	
		
	
	while(chances !=7)
	{
		match = false;  
		
		
		// User prompt
		if(str1!= rightword)
		{
		cout << "Enter a letter: " ; 
		cin >> letter;  
		}

		// Loop to match letters

		for( string::size_type i=0; i < str1.size(); i++)
		{
			if(str1.at(i) == letter)
			{
			secret.at(i) = letter;
			match = true;
			}
		
		}
		
		matchingoutputs(match,chances,secret, letter, str1, rightword);
		
	}
		
		
	
	
	if(str1==rightword)
						// I belive that this part is not returning the WON enum correctly. 
		return WON;
	
	if(chances==7)
		cout << "Sorry, The game is over." << endl;
		return LOST;
	
		

}




void main()

{	
	// Variables
	
	int coded= 0;
	string str1 = "";
	string star = "*";
	fin.open("input.txt");
	status = CONTINUE;
	char cont=' ';

	
	//Main functions
	do
	{
		DisplaynameAndGame();
		GetWord(str1);
		status=PlayHangman(str1);
		// This part is my attempt to have the status of the hangman game be updated. For instance if They said C for continue
		// then it would go through a selection process to update the right enum. 
		if((status= WON) || (status =LOST))
		cout <<"Enter 'C' to continue to play " << endl;
		cin >> cont;
		



	}
	while(status=CONTINUE); 
	
system("pause");

}
Last edited on
First thing I noticed is that the if statement on line 213 and the while on 221 are wrong. Instead of using the comparison operator ==, you used the assignment operator =.

This could be why it doesn't seem to respond to changes in status, since the if statement and the while statement both change the value themselves.

In addition, there seems to be an error on line 192...
Last edited on
I changed the = to ==. So the following statement is inside my hangman function.
1
2
3
4
if(rightword==str1)
	
		return WON;
	


Nothing comes back in main. I'm trying to figure out why. Also I just typed above this cout << rightword; to see what the value of rightword is in the hangman function and it wouldn;t output. This is weird. I have looked to make sure if is passed by reference so I can get it back in main. This is the whole mess.
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
//Selection for word guess
void guessTheword(string str1, int chances, string& rightword)
{	
	
	int win=1;
	char yesno=' ';
	
	if(chances <6 )																   //|| yesno =='Y')
	{
	cout << "Do you want to guess the word ,'Y' or 'N' ? " ;
	
	
	cin >> yesno;
	
	switch (yesno)
	{  
		case 'Y':
		cout << "Enter your word now: " ;
		
		cin >> rightword;
		
		if( rightword == str1)
		{
		cout << "Congratulations " << endl;
		if(win==1)
		cout << "You have won " << win << " game. " << endl;
		
		if(win>1)
		cout << "You have won " << win << " games. " << endl;
		win++;
		
		}
		else if(rightword !=str1)
		cout << "Sorry, that is not the word " << endl;
		break;
		
		case 'N': break;
	
		default : 
		cout << "Invalid choice." << endl;
			
	}
		
	}





}

// To display the the matching process
void matchingoutputs( bool match, int& chances, string secret, 
	char letter, string str1, string& rightword)
{
	if(rightword!=str1)
	{
		if(match)
		{
			cout << "The word is now " << secret << 
			'\n' << endl;
			
			guessTheword(str1, chances, rightword);
		
		
		
		}
		else if(!match)
		{
			cout << "Sorry, no occurrences of " << letter << 
			'\n' << endl;
			
		guessTheword(str1, chances, rightword);
			chances++;
		}


	}	

	

}

// Hangman function
gameEnum PlayHangman(const string str1)
{	
	
	string rightword ="";
	char choice = ' ';
	char letter=' ';
	string secret (str1.size(), '*' );
	bool match;
	int chances= 0;
	
	
	
	// First Iteration message	
	firstIteration(str1, secret);
	
	
		
	
	while(chances !=7)
	{
		match = false;  
		
		
		// User prompt
		if(str1!= rightword)
		{
		cout << "Enter a letter: " ; 
		cin >> letter;  
		}

		// Loop to match letters

		for( string::size_type i=0; i < str1.size(); i++)
		{
			if(str1.at(i) == letter)
			{
			secret.at(i) = letter;
			match = true;
			}
		
		}
		
		matchingoutputs(match,chances,secret, letter, str1, rightword);
		
	}
		
	
	
												// Plan. Write 2 different functions. One function that outputs number of wins 
	if(rightword==str1)
	
		return WON;
	
	
	if(chances== 7)
		cout << "Sorry, The game is over." << endl;
		return LOST;
	
		

}




void main()

{	
	// Variables
	
	int coded= 0;
	string str1 = "";
	string star = "*";
	fin.open("input.txt");
	status = CONTINUE;
	char cont=' ';

	
	//Main functions
	do
	{
		DisplaynameAndGame();
		GetWord(str1);
		status=PlayHangman(str1);
		
		 
		if((status== WON) || (status ==LOST))
		cout <<"Enter 'C' to continue to play " << endl;
		cin >> cont;
		



	}
	while(status==CONTINUE); 
	
system("pause");

}



See the enum LOST come back to main fine. See I want the other one to come WIN to come back also then in main I can fiddle with things the first step is getting my enums to main.


ANY IDEAS?
THANKS MUCH
For one thing you're trying to represent two different conditions in your enum.
Won vs. lost and continue vs. not continue. It can be done, but it's confusing.

What you want to do is at line 174, test cont and if Y, then set status to CONTINUE.
Last edited on
Yes but the enum for WON isn't even coming back from hangman thats what I'm troubled about.

Thanks
At lines 140/141, your indentation implies that both statements are conditional.
If that's what you meant, then you need braces around both statements and a return statement at line 144 in case chances != 7.

If you meant only line 140 to be conditional, then you're always returning LOST if rightword != str1.
Although that is a good idea it didn't fix my problem. I switched it around so it returns CONTINUE if chances!=7

it asks to enter a letter and i do then it says guess the word? I select yes
I enter the word and its right and it says congrats then says the how many games I have won.
But after that I want it to say enter 'C' to continue . That's the problem I win a game and its supposed to ask me if I want to continue it appears if I do it for LOST. I'm not sure whats going on. But this is really the problem as best as I can describe it .
At line 173, you do cin >> cont;
but don't do anything with cont.

I would suggest you add an enumeration for DONT_CONTINUE.
Then change 171-173 as follows:
1
2
3
4
5
6
7
8
9
if((status== WON) || (status ==LOST))
{  //  Note the braces	
    cout <<"Enter 'C' to continue to play " << endl;
    cin >> cont;
    if (cont == 'Y' || cont == 'y')
      status = CONTINUE;
    else 
      status = DONT_CONTINUE;
}

Your while condition should now work properly.

You also want to change line 139 as folllows:
1
2
3
4
5
6
7
if (chances == 7)
{  //  Braces added here also
    cout << "Sorry, The game is over." << endl;
    return DONT_CONTINUE;
}
else
  return LOST;

OK THANKS. I changed a bunch of things. My Issue now is if I guess the game it tells me to enter a letter. Which it should not it should go to main and say Do you want to continue? This happens in the guessTheword function where it says if rightword== str1
The messages below that appear but then when it goes back to hangman function it doesn't go to main and ask if I want to continue to play instead it asks me to enter a letter.
Also I can't get my loop to keep working in main. Thanks.

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
218
219
220
221
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

ifstream fin;

enum gameEnum{CONTINUE,WON,LOST} status;
	



// Display name and game
void DisplaynameAndGame()
{
	cout << "Word Guessing game by Jordan Lillie" << endl;
	


}



// Get word from file
string GetWord(string& str1)  
{	
	fin >> str1;
	
	
	
	
	
	return str1;

}


 //Messages for first iteration
void firstIteration(string str1, string secret)
{
	
		{ 
			cout << "Starting new game " << endl;
			cout << "My word has " << str1.length() << " characters." << endl;
			cout << "User word is " << secret << endl;
	
		}


}

//Selection for word guess
void guessTheword(string str1, int chances,string& secret)
{	
	string rightword="";
	int win=1;
	char yesno=' ';
	
	if(chances <6 )																 
	{
	cout << "Do you want to guess the word ,'Y' or 'N' ? " ;
	cin >> yesno;
	
	switch (yesno)
	{  
		case 'Y':
		cout << "Enter your word now: " ;
		
		cin >> rightword;
		
		if( rightword == str1)
		{
			str1==secret;
			cout << "Congratulations " << endl;
			cout << "Total wins: " << win << endl;
		}
		else if(rightword != str1)
		{
		cout << "Sorry, that is not the word " << endl;
		break;
		}
		case 'N': break;
		default : 
		cout << "Invalid choice." << endl;
		
	}
		
}





}

// To display the the matching process
void matchingoutputs( bool match, int& chances, string& secret, 
	char letter, string str1)
{
	if(secret != str1)
	{
		if(match)
		{
			cout << "The word is now " << secret << 
			'\n' << endl;
			guessTheword(str1, chances,secret);
		}
		else if(!match)
		{
			cout << "Sorry, no occurrences of " << letter << 
			'\n' << endl;
			guessTheword(str1, chances, secret);
			chances++;
		}
	}	
}

// Hangman function
gameEnum PlayHangman(const string str1)
{	
	
	
	char choice = ' ';
	char letter=' ';
	string secret (str1.size(), '*' );
	bool match;
	int chances= 0;
	
	// First Iteration message	
	firstIteration(str1, secret);
	
	while(chances != 7)
	{
		match = false;  
		
		
		// User prompt
		if(secret != str1)
		{
		cout << "Enter a letter: " ; 
		cin >> letter;  
		}
		else 
		{
			cout << "Good Job "<< str1 <<" is the word." << endl;
			return WON;
		}

		// Loop to match letters

		for( string::size_type i=0; i < str1.size(); i++)
		{
			if(str1.at(i) == letter)
			{
			secret.at(i) = letter;
			match = true;
			}
		}
		//Function for matching inputs to output messages
		matchingoutputs(match,chances,secret, letter, str1);
		
	}
		
	if(secret == str1)
	{
		return WON;
	}

	else if(chances == 7)
	{
		cout << "Sorry, The game is over." << endl;
		return LOST;
	}
	
	 else if(chances!=7)
	{
		return CONTINUE;
	}

	
}


void main()

{	
	// Variables
	string str1 = "";
	string star = "*";
	fin.open("input.txt");
    gameEnum status= LOST;
	char cont=' ';

	
	//Main functions
	do
	{
		DisplaynameAndGame();
		GetWord(str1);
		status=PlayHangman(str1);
		
		// Selection for game status
		if((status==WON) || (status == LOST))
		{
		cout <<"Do you want to continue to play? Enter 'Y' or 'N' " << endl;
		cin >> cont;
		}
		switch(cont)
		{
			case 'Y': status == CONTINUE;
			
		}
		
	}
	while(status==CONTINUE);


system("pause");

}
Figured out the letter problems I cannot keep the program going in main I think something is wrong with my loop.

Just main is the issue now. The loop
THanks
Scratch that I got it .... THANKS AGAIN FOR THE HELP!
Topic archived. No new replies allowed.