Hangman with Hint problem

I get this error messages from my code:
problem on line 193
[ERROR]expected primary expression before'{' token
[ERROR]expected primary expression before'.' token
[ERROR]expected primary expression before'[' token
please help me ,how can i fix it , thanks in advance

im using devc++

this is my 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
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
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <conio.h>
#include <cstdlib>
#include <windows.h>
#include <stdio.h>
#include <algorithm>

using namespace std;
void gotoxy(short x, short y)
{
	COORD pos={x,y};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

string THE_WORD;
int wrong, score;
string soFar;
string used;


bool match(char letter, string word);
char askGuess(string usedLettersStr); 
bool playAgain();

int main()
{
    clock_t t1,t2;
    t1=clock();
    t2=clock();
    float diff ((float)t2-(float)t1);
    cout<<diff<<endl;
    srand(time(0));
    
    int num, g, l;
enum fields {WORD, HINT};
    const string Game[5][2] = {
        						{"prince", "Nothing better than being blue blood!"},
    							{"poultry", " Is it better than meat?"},
                                {"mandarin", " Is it chineese?"},
                                {"minister", "Are you a priest?"},
                                {"betray", " Trustworthy?"}
                                };

    
    MENU:
	
	system("cls");
	system("color 07");
	cout<<"\n\n\n\n\t\t\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb";
    cout<<"\n\t\t\xdb\t\t\t\t\t\xdb\n\t\t\xdb\t\t\t\t\t\xdb";
    cout<<"\n\t\t\xdb\t    [1] New Game\t\t\xdb"<<endl;
 	cout<<"\t\t\xdb\t    [2] Instructions\t\t\xdb"<<endl;
 	cout<<"\t\t\xdb\t    [3] Exit\t\t\t\xdb"<<endl;
 	cout<<"\t\t\xdb\t\t\t\t\t\xdb\n\t\t\xdb\t\t\t\t\t\xdb";
 	cout<<"\n\t\t\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb";
 	
 do { 
 	CHOICE:
 	gotoxy(1,12);cout<<"\n\n\t\tChoose a number to continue: ";
 	gotoxy(45,14);std::cin>>num;
	 if (num>=4) {gotoxy(44,14);cout<<"  "; gotoxy(16,15);cout<<"PLEASE ENTER A VALID VALUE!!";} 
	  } while (num>=4);
 switch (num) { 
 	case 2:
 	TWO:
  {
		   	 		 
	   	   				 system ("cls");
	            cout<< "\n\t\t\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb";
    			cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
				cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\t\    How to Play ..\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\tIn order to play the game,       \xdb";
		   	    cout<< "\n\t\t\xdb follow these simple steps :)\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
	   	   		cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\tMAIN GOAL OF THE GAME..\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\tThere will be words hidden in *, \xdb";
		   	    cout<< "\n\t\t\xdb you should guess it with only THREE (3)\xdb";
		   	    cout<< "\n\t\t\xdb TRIALS.\t\t\t\t \xdb";
	   	   		cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
	   	   		cout<< "\n\t\t\xdb\tJust key in a letter for you to  \xdb";
	   	   		cout<< "\n\t\t\xdb know if the word is included, think    \xdb";
	   	   		cout<< "\n\t\t\xdb carefully to complete the word.\t \xdb";
	   	   		cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
	   	   		cout<< "\n\t\t\xdb\tIf you fail to input the correct \xdb";
	   	   		cout<< "\n\t\t\xdb letter, the game is OVER!\t\t \xdb";
	   	   		cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
				cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
	 		    cout<< "\n\t\t\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb";
			   	cout<< "\n\t\t\t\t[Enter]";
				while ((l= getch()) != 13)
	   	   				 printf ("[ENTER]\n", l);
			   system ("cls");
			   goto MENU;
			   } break ;
			   
//For EXITING the program..
	case 3:
	   THREE:
	   {
	   	  		  system ("cls");
	   	  		  cout<<"Are you sure you want to exit the game? [Y/N]: ";
	   	  		  std::cin>>g;

				  switch (g)
				  {
				   		 case 'y':
						 	  {
						 	  system ("cls");
				   		cout<<"Thank You for using the program. Bye :D\n";
				   		cout<<"please press ENTER key 'twice' to exit.";
				   		getch();
				   		break;
						}
						case 'n':
					    {
						system ("cls");
						goto MENU;
						break;
						}
						}
						system ("pause>nul");
						} break;

//Game..
		case 1:				
 	{
	   		 system ("cls");

 			  bool done = false;
 			  do
			   { 
    		   const int MAX_WRONG = 3;  

    		   int choice = rand() % 5;
    	string TheWord = Game[choice][WORD];
    	string TheHint = Game[choice][HINT];            

    		   soFar = string(TheWord.size(), '*');          
    		   used = "";      
    		   while ((wrong < MAX_WRONG) && (soFar != TheWord))
    		   { 
        	   cout << "\n\nYou have " << (MAX_WRONG - wrong) << " incorrect guesses left.\n";
        	   cout << "\nSo far, the word is:\n" << soFar <<"\t"<< TheHint << endl;
	
        	   used += askGuess(used);



    		   } 
    		   if (wrong == MAX_WRONG)
    		   {
    		   	system ("cls");
      		   cout << "\nGAME OVER!!!";
      		   score=0;
    		   }

    		   cout << "\nThe word was " << TheWord << endl;
wrong=0;
			   } while(playAgain());

			   return 0;
			   } break; }
		 

}
inline bool match(char letter, string word)
{
       return ( word.find(letter) != string::npos );
}

char askGuess(string usedLettersStr)
{
        char guess;
        cout << "\n\nEnter your guess: ";
        cin >> guess;
        guess = toupper(guess); 
        while (match(guess, used))
        {
            cout << "\nYou've already guessed " << guess << endl;
            cout << "Enter your guess: ";
            cin >> guess;
            guess = toupper(guess);
        }



        if (match(guess, WORD))
        {
            cout << "That's right! " << guess << " is in the word.\n";

           score=score+10;
           cout<<"Score : "<<score;
            for (int i = 0; i < WORD.length(); ++i)
                if (WORD[i] == guess)
                    soFar[i] = guess;
        }
        else
        {
            cout << "Sorry, " << guess << " isn't in the word.\n";
            ++wrong;
        }
}

bool playAgain() 
{
     char again;
     cout << "\n\nWould you like to play again? <y/n>: ";
     cin >> again;

     cin.clear(); 
     cin.ignore();

     again = toupper(again);

     system("cls");

     return (again == 'Y');
}
Last edited on
please help me with this

Well, looking at your code WORD is part of the fields enum, shouldn't this be THE_WORD? - your trying to read the length of something that isn't a string amongst other things.

Lastly, askGuess is meant to return a char, yet I see that you don't do that - there may be other issues as I've not had a chance to load it up in my compiler.

id replaced it with THE_WIRD and it succesfully compile, but when im inside the game even if i enter a correct guessed it considerend it wrong

this the code new 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
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 <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <conio.h>
#include <cstdlib>
#include <windows.h>
#include <stdio.h>
#include <algorithm>

using namespace std;
void gotoxy(short x, short y)
{
	COORD pos={x,y};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

string THE_WORD;
int wrong, score;
string soFar;
string used;


bool match(char letter,string word);
char askGuess(string usedLettersStr); 
bool playAgain();

int main()
{
    clock_t t1,t2;
    t1=clock();
    t2=clock();
    float diff ((float)t2-(float)t1);
    cout<<diff<<endl;
    srand(time(0));
    
    int num, g, l;
enum fields {WORD, HINT};
    const string Game[5][2] = {
        						{"prince", "Nothing better than being blue blood!"},
    							{"poultry", " Is it better than meat?"},
                                {"mandarin", " Is it chineese?"},
                                {"minister", "Are you a priest?"},
                                {"betray", " Trustworthy?"}
                                };

    
    MENU:
	
	system("cls");
	system("color 07");
	cout<<"\n\n\n\n\t\t\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb";
    cout<<"\n\t\t\xdb\t\t\t\t\t\xdb\n\t\t\xdb\t\t\t\t\t\xdb";
    cout<<"\n\t\t\xdb\t    [1] New Game\t\t\xdb"<<endl;
 	cout<<"\t\t\xdb\t    [2] Instructions\t\t\xdb"<<endl;
 	cout<<"\t\t\xdb\t    [3] Exit\t\t\t\xdb"<<endl;
 	cout<<"\t\t\xdb\t\t\t\t\t\xdb\n\t\t\xdb\t\t\t\t\t\xdb";
 	cout<<"\n\t\t\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb";
 	
 do { 
 	CHOICE:
 	gotoxy(1,12);cout<<"\n\n\t\tChoose a number to continue: ";
 	gotoxy(45,14);std::cin>>num;
	 if (num>=4) {gotoxy(44,14);cout<<"  "; gotoxy(16,15);cout<<"PLEASE ENTER A VALID VALUE!!";} 
	  } while (num>=4);
 switch (num) { 
 	case 2:
 	TWO:
  {
		   	 		 
	   	   				 system ("cls");
	            cout<< "\n\t\t\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb";
    			cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
				cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\t\    How to Play ..\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\tIn order to play the game,       \xdb";
		   	    cout<< "\n\t\t\xdb follow these simple steps :)\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
	   	   		cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\tMAIN GOAL OF THE GAME..\t\t \xdb";
		   	    cout<< "\n\t\t\xdb\tThere will be words hidden in *, \xdb";
		   	    cout<< "\n\t\t\xdb you should guess it with only THREE (3)\xdb";
		   	    cout<< "\n\t\t\xdb TRIALS.\t\t\t\t \xdb";
	   	   		cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
	   	   		cout<< "\n\t\t\xdb\tJust key in a letter for you to  \xdb";
	   	   		cout<< "\n\t\t\xdb know if the word is included, think    \xdb";
	   	   		cout<< "\n\t\t\xdb carefully to complete the word.\t \xdb";
	   	   		cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
	   	   		cout<< "\n\t\t\xdb\tIf you fail to input the correct \xdb";
	   	   		cout<< "\n\t\t\xdb letter, the game is OVER!\t\t \xdb";
	   	   		cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
				cout<< "\n\t\t\xdb\t\t\t\t\t \xdb";
	 		    cout<< "\n\t\t\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb";
			   	cout<< "\n\t\t\t\t[Enter]";
				while ((l= getch()) != 13)
	   	   				 printf ("[ENTER]\n", l);
			   system ("cls");
			   goto MENU;
			   } break ;
			   
//For EXITING the program..
	case 3:
	   THREE:
	   {
	   	  		  system ("cls");
	   	  		  cout<<"Are you sure you want to exit the game? [Y/N]: ";
	   	  		  std::cin>>g;

				  switch (g)
				  {
				   		 case 'y':
						 	  {
						 	  system ("cls");
				   		cout<<"Thank You for using the program. Bye :D\n";
				   		cout<<"please press ENTER key 'twice' to exit.";
				   		getch();
				   		break;
						}
						case 'n':
					    {
						system ("cls");
						goto MENU;
						break;
						}
						}
						system ("pause>nul");
						} break;

//Game..
		case 1:				
 	{
	   		 system ("cls");

 			  bool done = false;
 			  do
			   { 
    		   const int MAX_WRONG = 3;  

    		   int choice = rand() % 5;
    	 THE_WORD = Game[choice][WORD];
    	string TheHint = Game[choice][HINT];            

    		   soFar = string(THE_WORD.size(), '*');          
    		   used = "";      
    		   while ((wrong < MAX_WRONG) && (soFar != THE_WORD))
    		   { 
        	   cout << "\n\nYou have " << (MAX_WRONG - wrong) << " incorrect guesses left.\n";
        	   cout << "\nSo far, the word is:\n" << soFar <<"\t"<< TheHint << endl;
	
        	   used += askGuess(used);



    		   } 
    		   if (wrong == MAX_WRONG)
    		   {
    		   	system ("cls");
      		   cout << "\nGAME OVER!!!";
      		   score=0;
    		   }

    		   cout << "\nThe word was " << THE_WORD << endl;
wrong=0;
			   } while(playAgain());

			   return 0;
			   } break; }
		 

}
inline bool match(char letter,string WORD)
{
       return ( WORD.find(letter) != string::npos );
}

char askGuess(string usedLettersStr)
{
        char guess;
        cout << "\n\nEnter your guess: ";
        cin >> guess;
        guess = toupper(guess); 
        while (match(guess, used))
        {
            cout << "\nYou've already guessed " << guess << endl;
            cout << "Enter your guess: ";
            cin >> guess;
            guess = toupper(guess);
        }



        if (match(guess, THE_WORD))
        {
            cout << "That's right! " << guess << " is in the word.\n";

           score=score+10;
           cout<<"Score : "<<score;
            for (int i = 0; i < THE_WORD.length(); ++i)
               {
                if (THE_WORD[i] == guess)
                    soFar[i] = guess;}
        }
        else
        {
            cout << "Sorry, " << guess << " isn't in the word.\n";
            ++wrong;
        }
}

bool playAgain() 
{
     char again;
     cout << "\n\nWould you like to play again? <y/n>: ";
     cin >> again;

     cin.clear(); 
     cin.ignore();

     again = toupper(again);

     system("cls");

     return (again == 'Y');
}

Line 151 you are adding whatever is returned from askGuess to string used yet you dont actually return anything from the askGuess function.
how can i fix it? should i remove it?
Topic archived. No new replies allowed.