Checking a Match After Each Guess

So I had a previous thread about functions. I have all my functions down, I hope lol So now, I want to check each guess the user enters against the computers seeded random guess after each time the user inputs a guess. Right now, my output is asking for all 5 guesses, and then says Sorry your card is not a match and starts the process all over again, not displaying my displaycards func or display esp func. Any input is much appreciated.

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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
  #include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>


using namespace std;


void DisplayInstructions ( );  
void GenerateCorrectCards (int *);  
int GetGuess ( );  
bool  CheckMatch (int , int *); 
void DisplayCards (int *, int *); 
void DisplayESP (int); 

//int userSelect[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};

int main()
{
	
	int generatedCards[5];

	int const CARDS =18;
	

	int user[5];

	
	int i;
const char *deck [CARDS]={"red circle","red square","red triangle","blue circle","blue square",
	 "blue triangle","yellow circle","yellow square","yellow triangle","orange circle",
	 "orange square" ,"orange triangle","purple circle","purple square",
     "purple triangle","green circle","green square","green triangle"};
	
	
	srand ( time(NULL) );//Seeds the random generator once at the beginning
	
	
	DisplayInstructions();
	cout<<"\n";
		
   
	GenerateCorrectCards (generatedCards);//generates the computers cards
	for ( i=0; i<5; i++){

         *(user + i) = GetGuess(); 
         
         
         CheckMatch (i,generatedCards);
        
         
int currentGuess = GetGuess();        
//check if currentGuess is a duplicate before updating user array

//if not duplicate, check if it matches computer hand
bool match = CheckMatch (i, generatedCards);

          
}

 cout<<"Player's Choice "<< "   " << "Computer's Choice "<<"\n";
     cout<<"*******************************************"<<"\n";
    for (i=0; i < 5; i++)
     {   
          

         DisplayCards((user+i),generatedCards);

        
}

DisplayESP(i);

	
	
	
//	for (char Z = 'Q' ; z == 'Q' || z == 'q';  ){
//	
//	cout<<"Do you want to play another round?Enter q to quit."

}
void DisplayInstructions()
{
	
	cout <<	"The computer will generate a deck of 18 cards.\n"
		 << "There are 3 shapes: Circle, square, and triangle.\n"
		 << "There are 6 colors: Red, blue, yellow, orange, purple, and green.\n"
		 << "Pick a shape and then a color.\n"
		 << "Do this 5 times and see if your predictions match what the computer picked,\n checking your ESP level!\n";
	
}



void GenerateCorrectCards(int *generatedCards)
{
	
	int i;
    int selectedInt;
    int alreadySelect = 0;
    int successfulSelections = 0;
    
    while (successfulSelections < 5) {
        selectedInt = (rand() % 18) + 1;				//mod for the deck of 18

        if (successfulSelections==0) {
            *(generatedCards)=selectedInt;
        }
 
        for (int i=0;i<successfulSelections;i++) {			//checking for dup
            if (*(generatedCards+i)==selectedInt) {
                alreadySelect=1;
                break;
            } else {
                alreadySelect=0;

                *(generatedCards+successfulSelections)=selectedInt;
            }
        }

        if (alreadySelect==0) {
            successfulSelections++;
        }
    }
}
    
    
    
	


int GetGuess ( )
{
	int const CARDS=18;
	std::string deck [CARDS]={"red circle","red square","red triangle","blue circle","blue square",
	 "blue triangle","yellow circle","yellow square","yellow triangle","orange circle",
	 "orange square" ,"orange triangle","purple circle","purple square",
     "purple triangle","green circle","green square","green triangle"};
     


std::string to_lower( std::string str ); // make everything lower case
 for (int i=0;i<5;i++)
    {
    	std::string color,shape,combo,userSelect;
    	
    	
    	cout<<"Please choose a card with a color first, and then a shape.";
	cin>>color>>shape;
	combo= color + " " +shape;
	combo=userSelect;
	
	
  if (userSelect=="red circle")
  		return 1;
  	else if	(userSelect=="red triangle")
  		return 2;
  	else if(userSelect=="red square")
  		return 3;
  	else if(userSelect=="blue circle")
  	
  	return 4;
  	else if (userSelect=="blue triangle")
  	
  	return 5;
  	else if(userSelect=="blue square")
  	
  	return 6;
  	else if(userSelect=="yellow circle")
  	
  	return 7;
  	else if(userSelect=="yellow triangle")
  	
  	return 8;
  	else if(userSelect=="yellow square")
  	
  	return 9;
  	else if (userSelect=="orange circle")
  	
  	return 10;
  	else if (userSelect=="orange triangle")
  	
  	return 11;
  	else if(userSelect=="orange square")
  	
  	return 12;
  	else if (userSelect=="purple circle")
  	
  	return 13;
  	else if (userSelect=="purple triangle")
  	
  	return 14;
  	else if (userSelect=="purple square")
  	
  	return 15;
  	else if(userSelect=="green circle")
  	
  	return 16;
  	else if ( 	userSelect=="green triangle")
 
  	return 17;
  	else if  (userSelect=="green square")
  	
  	return 18;
  	
  	
  	
  
}
    }
    bool  CheckMatch (int user, int *generatedCards)
    {
    	
    	for (int i=0;i<5;i++) {
        if (*(generatedCards+i)==user) {
            cout << "Your card matches!" << "\n";
            return true;
    
        }
    }
    cout << "Sorry, your card does not match." << "\n";
    return false;
}
    	
void DisplayCards (int *user, int *GeneratedCorrectCards)
    	{
    	
//DisplayCards is passed the computer’s and the player’s card arrays. 
//It displays the two sets of cards side by side, by color and shape, not by integer! Has no cin's.
//
//Hint:  Use the card mapping array to look up the integer and get the string representing the card.
switch (*(user))
	{
		case 0:
			cout << "red circle"<<endl;
			break;
		case 1:
			cout<< "red square"<<endl;
			break;
		case 2:
			cout << "red triangle" <<endl;
			break;
		case 3:
			cout << "blue circle" <<endl;
			break;
		case 4:
			cout << "blue square" <<endl;
			break;
		case 5:
			cout << "blue triangle" <<endl;
			break;
		case 6:
			cout << "yellow circle"<<endl;
			break;
		case 7:
			cout << "yellow square" <<endl;
			break;
		case 8:
			cout << "yellow triangle" <<endl;
			break;
		case 9:
			cout << "purple circle" <<endl;
			break;
		case 10:
			cout << "purple square" <<endl;
			break;
		case 11:
			cout << "purple triangle" <<endl;
			break;
		case 12:
			cout << "orange circle" <<endl;
			break;
		case 13:
			cout << "orange square"<<endl;
			break;
		case 14:
			cout << "orange triangle" <<endl;
			break;
		case 15:
			cout << "green circle" <<endl;
			break;
		case 16:
			cout << "green square" <<endl;
			break;
		case 17:
			cout << "green triangle" <<endl;
			break;
		
			
	}
}
    		
    void DisplayESP (int i) {

switch (i){


case 0:
	if(i==0)
	cout<<"Level 1: Don't ever go to the casino's!";
	break;
case 1:
		if(i==1 || 2)
		cout<<"Level 2: Some ESP, slot machines may be best.";
		break;
case 2:
			if (i==3||4)
			cout<<"Level 3: Lots of ESP.  Go play the Powerball!";
			break;
case 3:
			if (i==5)
			cout<<"You are a psychic! You must go to the casinos and become rich!";
			break;
}
//	0 matches:  “Level 1: No ESP at all!”
//	1-2 matches:  “Level 2: Some ESP, keep working on it!”
//	3-4 matches:  “Level 3: Lots of ESP, try Powerball!”
//	   5 matches:  “Level 4: ESP expert! Host a TV show!”

	
	
	
	
	}
//DisplayESP is passed the number of matches.  It displays the appropriate ESP Level message. Has no cin's.
//		
    		
    
    	
    

Anybody?? I've been playing with my code for hours now and can't figure how to achieve using my bool func to check after each answer...... gahhhh Im in desperation mode lol
First: std::string to_lower(std::string str); // make everything lower case
You didn't make any assignment. Your compiler will tell you that the return value of that function call was unused. Do something like this str = std::to_lower(str) if you want to make "str" all lower case.

If you want it to check every answer after every time the user enters it, you need to call that function after every single guess the user makes.
Ahh I didn't even catch that.

So, I should call checkmatch in Getguess?

Edit: The issue is in my assignment req I have to call checkmatch in a loop in main
Last edited on
Amg I figured it out. The for loop in getguess had it going and going.

So.. now my issue is it does not stop after 5 times, and it does not use the displayesp or displaycards. Any ideas?
Topic archived. No new replies allowed.