Help with unrecognized input

This is a function call for my Wheel of Fortune game. And I'm getting a hard time pinpointing where did i go wrong, When i Run the program after:
Line 50 --
1
2
3
cout << "Guess a consonant letter or Solve the word" << endl;
getline(cin,guess2);
cin.ignore(256, '\n');

its directing to the:
Line 81 --
1
2
else if(copy2.find(guess2) != -1){	
cout << endl << "Correct letter!" << endl;

whatever letter/word i input. sorry, if its confusing, its hard to explain without running it directly.

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
  int lvl2(struct Player st[],int& itemcount)
{
	st[itemcount].money = st[itemcount].total;
	st[itemcount].wheelval = 0; st[itemcount].total = 0;
	system("cls");
	cout << "Hello again, " << st[itemcount].name << ". Are you ready for the next level? \nYou start the game with $" << st[itemcount].money << "." << endl;
	wait(seconds);
	int seconds = 1, wrong = 0, choice;
	wait(seconds);
	vector< string > dictionary2;
	getDictionary2( dictionary2 );
	int randomWord2;
	randomWord2 = rand() % dictionary2.size();
	string word2 = dictionary2[ randomWord2 ];
	char key = ' ',key2 = ' ', key3=' ', lvl;
	locale loc2;
	string copy2 = word2;
    string Underscore2, guess2;
  	for(int i=0; i!=word2.length(); i++){
    	if(word2.at(i) == ' '){
      	Underscore2 += " ";
    	} else{
      		Underscore2 += "-";
    		}
  	}
//  	string usedLetter = "";
  	while(1){
//  	spin:
  	wait(seconds);
  	system("cls");
  	cout << "PRESS ANY KEY TO SPIN" << endl;
	allwheel();
	spin(st, itemcount);
	wait(seconds); 
//  	for (string::size_type i=0; i<usedLetter.length(); ++i)
//  	usedLetter = toupper(usedLetter[i],loc);
//  	cout << "\nYou've used this letters: " << usedLetter << endl;
//  	system("cls");
    st[itemcount].total = st[itemcount].wheelval + st[itemcount].money;
    st[itemcount].money = st[itemcount].total;
    st[itemcount].wheelval = 0;
    back:
    again:
	cout << endl;
    cout << endl << Underscore2 << endl << endl;
    cout << "The Category of the Word is TITLE OF MOVIES." << endl;
    cout << "There are " << word2.length() << " letters and spaces" << endl;
    cout << "You have " << 7 - wrong << " more tries left" << endl;
	cout << "You currently have $" << st[itemcount].total << endl;
    cout << "Guess a consonant letter or Solve the word" << endl;
  	getline(cin,guess2);
  	cin.ignore(256, '\n');
//    for (string::size_type i=0; i<guess.length(); ++i)
//    guess = toupper(guess[i],loc);
    if(guess2.length() > 1){
      if(guess2 == word2){
        cout << "Congratulations, you guessed the word! +$7000" << endl;
        st[itemcount].total = st[itemcount].total + 7000;
    	cout << "Proceed to the next level?(y/n)";
    	cin >> lvl;
    	if(lvl == 'y' || lvl == 'Y'){
    	  	lvl2(st,itemcount);
		  	}else
			cout << "You've earned $" << st[itemcount].total << endl;
        	exit(1);
      	}else{
        	cout << "Wrong word " << endl;
        	wrong++;
      		}
    }
	if(guess2 == "A" ||guess2 == "E" ||guess2 == "I" ||guess2 == "O" ||guess2 == "U")
     {
     	cout << "Invalid Letter, you need to buy the Vowel\n";
     	wait(seconds);
     	goto again;
	 }
//	 else if(! checkLetter(key,guess,word))
//	 {
//	 	cout << "You've already guessed this letter!";
//	 }
	else if(copy2.find(guess2) != -1){	
        cout << endl << "Correct letter!" << endl;
        while(copy2.find(guess2) != -1){
        Underscore2.replace(copy2.find(guess2), 1, guess2);
        copy2.replace(copy2.find(guess2), 1, "_");
        if(Underscore2 == word2){
    	cout << "Congratulations, you guessed the word! +$7000" << endl;
    	st[itemcount].total = st[itemcount].total + 7000;
    	cout << "Proceed to the next level?(y/n)";
    	cin >> lvl;
    	if(lvl == 'y' || lvl == 'Y'){
    	  	lvl2(st,itemcount);
		  	}else
			cout << "You've earned $" << st[itemcount].total << endl;
        	exit(1);
 		   }
		  loop:
          cout << Underscore2 << endl;
          wait(seconds);
          cout << "You currently have $" << st[itemcount].total << endl;
          st[itemcount].money = st[itemcount].total;
	cout << "Buy a Vowel-$450ea(V), Spin(space), or Solve(S)" << endl;
	key2 = _getch();
	switch(key2){
		case 'V': case 'v':{
			if(st[itemcount].total<450){
			cout << "You have Insufficient Money." << endl;
			goto back;
			}
			buy:
			cout << "What vowel do you want to buy?" << endl << "A  E  I  O  U" << endl;
			key3 = _getch();
			switch (key3){
				case 'A': case 'a':{
					guess2 = 'A';		
					st[itemcount].total = st[itemcount].total - 450; 
					if(copy2.find(guess2) != -1){
        			while(copy2.find(guess2) != -1){
         			Underscore2.replace(copy2.find(guess2), 1, guess2);
         			copy2.replace(copy2.find(guess2), 1, "_");
          			goto loop;
     				 		}
  					}
  				 break;
				}
				case 'E': case 'e':{
					guess2 = 'E';
					st[itemcount].total = st[itemcount].total - 450;
					if(copy2.find(guess2) != -1){
        			while(copy2.find(guess2) != -1){
         			Underscore2.replace(copy2.find(guess2), 1, guess2);
         			copy2.replace(copy2.find(guess2), 1, "_");
          			goto loop;
     				 		}
  					}
					break;
				}
				case 'I': case 'i':{
					guess2 = 'I';
					st[itemcount].total = st[itemcount].total - 450;
					if(copy2.find(guess2) != -1){
        			while(copy2.find(guess2) != -1){
         			Underscore2.replace(copy2.find(guess2), 1, guess2);
         			copy2.replace(copy2.find(guess2), 1, "_");
          			goto loop;
     				 		}
  					}
					break;
				}
				case 'O': case 'o':{
					guess2 = 'O';
					st[itemcount].total = st[itemcount].total - 450;
					if(copy2.find(guess2) != -1){
        			while(copy2.find(guess2) != -1){
         			Underscore2.replace(copy2.find(guess2), 1, guess2);
         			copy2.replace(copy2.find(guess2), 1, "_");
          			goto loop;
     				 		}
  					}
					break;
				}
				case 'U': case 'u':{
					guess2 = 'U';
					st[itemcount].total = st[itemcount].total - 450;
					if(copy2.find(guess2) != -1){
        			while(copy2.find(guess2) != -1){
         			Underscore2.replace(copy2.find(guess2), 1, guess2);
         			copy2.replace(copy2.find(guess2), 1, "_");
          			goto loop;
     				 		}
  					}
					break;
				}default: cout << "Invalid Input, only Vowel" << endl;
				goto buy;
			}
			break;
		}
		case ' ':{
			//goto spin;
			break;
		}
		case 'S': case 's':{
			cout << "Solve it " << endl;
			getline(cin, guess2);
			if(guess2 == word2){
        		cout << "Congratulations, you guessed the word! +$7000" << endl;
        		st[itemcount].total = st[itemcount].total + 7000;
    			cout << "Proceed to the next level?(y/n)";
    			cin >> lvl;
    			if(lvl == 'y' || lvl == 'Y'){
    			  	lvl2(st,itemcount);
		  		}else
				cout << "You've earned $" << st[itemcount].total << endl;
        		exit(1);
      		} else{
        	cout << "Wrong word " << endl;
        	wrong++;
    			}
			break;
		}
		default: 
		cout << "Invalid Input, only (V),(space), or (S)" << endl;
		goto loop;
	}
    }
}
    else{
      	cout << guess2 << " is an incorrect word/letter." << endl;
      	int seconds = 2;
     	wait(seconds);
      	wrong++;  
    	}if(wrong == 7){
      	cout << "You Lose! The word was: " << word2 << endl;
      	system("pause");
      	break;
    	}	
	}
}
Last edited on
I would guess that that cin.ignore() call is part of the problem. Remember getline() extracts the end of line character and discards it, so that ignore will sit there and wait until the user enters another entry, which will then be discarded.

You really should stop using all of those goto statements and learn to use one of the other more acceptable loop constructs along with functions. IMO this function is trying to do too much and should be broken up into smaller functions.
thank you for the heads up, i'll try another method and remove getline. and as for goto, im still learning alternatives for something so similar like that, so i used the goto for the time being.
what i dont understand is, in my other function, that is similar to this, it works, but here it doesnt. the first level, this is the second lvl

my function for the first level, very similar to my int lvl2(); but this one works.
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
int game(struct Player st[],int& itemcount)
{
	st[itemcount].money = 0;
	cout << "What is the name of the Player? " << endl;
	cin.getline(st[itemcount].name,80);
	system("cls");
	cout << "Hello, " << st[itemcount].name << ". You start the game with $" << st[itemcount].money << "." << endl;
	int seconds = 1, wrong = 0, choice;
	wait(seconds);
	vector< string > dictionary;
	getDictionary( dictionary );
	int randomWord;
	randomWord = rand() % dictionary.size();
	string word = dictionary[ randomWord ];
	char key = ' ',key2 = ' ', key3=' ', lvl;
	locale loc;
	string copy = word;
    string Underscore, guess;
  	for(int i=0; i!=word.length(); i++){
    	if(word.at(i) == ' '){
      	Underscore += " ";
    	} else{
      		Underscore += "-";
    		}
  	}
//  	string usedLetter = "";
  	while(1){
//  	spin:
  	wait(seconds);
  	system("cls");
  	cout << "PRESS ANY KEY TO SPIN" << endl;
	allwheel();
	spin(st, itemcount);
	wait(seconds); 
//  	for (string::size_type i=0; i<usedLetter.length(); ++i)
//  	usedLetter = toupper(usedLetter[i],loc);
//  	cout << "\nYou've used this letters: " << usedLetter << endl;
//  	system("cls");
    st[itemcount].total = st[itemcount].wheelval + st[itemcount].money;
    st[itemcount].money = st[itemcount].total;
    st[itemcount].wheelval = 0;
    back:
    again:
	cout << endl;
    cout << endl << Underscore << endl << endl;
    cout << "The Category of the Word is OBJECT." << endl;
    cout << "There are " << word.length() << " letters and spaces" << endl;
    cout << "You have " << 8 - wrong << " more tries left" << endl;
	cout << "You currently have $" << st[itemcount].total << endl;
    cout << "Guess a consonant letter or Solve the word" << endl;
  	getline(cin,guess);
//    for (string::size_type i=0; i<guess.length(); ++i)
//    guess = toupper(guess[i],loc);
    if(guess.length() > 1){
      if(guess == word){
        cout << "Congratulations, you guessed the word! +$5000" << endl;
        st[itemcount].total = st[itemcount].total + 5000;
    	cout << "Proceed to the next level?(y/n)";
    	cin >> lvl;
    	if(lvl == 'y' || lvl == 'Y'){
    	  	lvl2(st,itemcount);
		  	}else
			cout << "You've earned $" << st[itemcount].total << endl;
        	exit(1);
      	}else{
        	cout << "Wrong word " << endl;
        	wrong++;
      		}
    }
	if(guess == "A" ||guess == "E" ||guess == "I" ||guess == "O" ||guess == "U")
     {
     	cout << "Invalid Letter, you need to buy the Vowel\n";
     	wait(seconds);
     	goto again;
	 }
//	 else if(! checkLetter(key,guess,word))
//	 {
//	 	cout << "You've already guessed this letter!";
//	 }
	else if(copy.find(guess) != -1){	
        cout << endl << "Correct letter!" << endl;
        while(copy.find(guess) != -1){
        Underscore.replace(copy.find(guess), 1, guess);
        copy.replace(copy.find(guess), 1, "_");
        if(Underscore == word){
    	cout << "Congratulations, you guessed the word! +$5000" << endl;
    	st[itemcount].total = st[itemcount].total + 5000;
    	cout << "Proceed to the next level?(y/n)";
    	cin >> lvl;
    	if(lvl == 'y' || lvl == 'Y'){
    	  	lvl2(st,itemcount);
		  	}else
			cout << "You've earned $" << st[itemcount].total << endl;
        	exit(1);
 		   }
		  loop:
          cout << Underscore << endl;
          wait(seconds);
          cout << "You currently have $" << st[itemcount].total << endl;
          st[itemcount].money = st[itemcount].total;
	cout << "Buy a Vowel-$400ea(V), Spin(space), or Solve(S)" << endl;
	key2 = _getch();
	switch(key2){
		case 'V': case 'v':{
			if(st[itemcount].total<400){
			cout << "You have Insufficient Money." << endl;
			goto back;
			}
			buy:
			cout << "What vowel do you want to buy?" << endl << "A  E  I  O  U" << endl;
			key3 = _getch();
			switch (key3){
				case 'A': case 'a':{
					guess = 'A';		
					st[itemcount].total = st[itemcount].total - 400; 
					if(copy.find(guess) != -1){
        			while(copy.find(guess) != -1){
         			Underscore.replace(copy.find(guess), 1, guess);
         			copy.replace(copy.find(guess), 1, "_");
          			goto loop;
     				 		}
  					}
  				 break;
				}
				case 'E': case 'e':{
					guess = 'E';
					st[itemcount].total = st[itemcount].total - 400;
					if(copy.find(guess) != -1){
        			while(copy.find(guess) != -1){
         			Underscore.replace(copy.find(guess), 1, guess);
         			copy.replace(copy.find(guess), 1, "_");
          			goto loop;
     				 		}
  					}
					break;
				}
				case 'I': case 'i':{
					guess = 'I';
					st[itemcount].total = st[itemcount].total - 400;
					if(copy.find(guess) != -1){
        			while(copy.find(guess) != -1){
         			Underscore.replace(copy.find(guess), 1, guess);
         			copy.replace(copy.find(guess), 1, "_");
          			goto loop;
     				 		}
  					}
					break;
				}
				case 'O': case 'o':{
					guess = 'O';
					st[itemcount].total = st[itemcount].total - 400;
					if(copy.find(guess) != -1){
        			while(copy.find(guess) != -1){
         			Underscore.replace(copy.find(guess), 1, guess);
         			copy.replace(copy.find(guess), 1, "_");
          			goto loop;
     				 		}
  					}
					break;
				}
				case 'U': case 'u':{
					guess = 'U';
					st[itemcount].total = st[itemcount].total - 400;
					if(copy.find(guess) != -1){
        			while(copy.find(guess) != -1){
         			Underscore.replace(copy.find(guess), 1, guess);
         			copy.replace(copy.find(guess), 1, "_");
          			goto loop;
     				 		}
  					}
					break;
				}default: cout << "Invalid Input, only Vowel" << endl;
				goto buy;
			}
			break;
		}
		case ' ':{
			//goto spin;
			break;
		}
		case 'S': case 's':{
			cout << "Solve it biatch" << endl;
			getline(cin, guess);
			if(guess == word){
        		cout << "Congratulations, you guessed the word! +$5000" << endl;
        		st[itemcount].total = st[itemcount].total + 5000;
    			cout << "Proceed to the next level?(y/n)";
    			cin >> lvl;
    			if(lvl == 'y' || lvl == 'Y'){
    			  	lvl2(st,itemcount);
		  		}else
				cout << "You've earned $" << st[itemcount].total << endl;
        		exit(1);
      		} else{
        	cout << "Wrong word " << endl;
        	wrong++;
    			}
			break;
		}
		default: 
		cout << "Invalid Input, only (V),(space), or (S)" << endl;
		goto loop;
	}
    }
}
    else{
      	cout << guess << " is an incorrect word/letter." << endl;
      	int seconds = 2;
     	wait(seconds);
      	wrong++;  
    	}if(wrong == 8){
      	cout << "You Lose! The word was: " << word << endl;
      	system("pause");
      	break;
    	}	
	}
}
thank you for the heads up, i'll try another method and remove getline.

The getline() is probably not the problem, the problem is probably the ignore().

im still learning alternatives for something so similar like that,

I suggest you stop what you're doing and do this learning now. You should forget that you have ever heard about the goto statement.

Topic archived. No new replies allowed.