No string displaying // Windows error // Need help for my Proyect! Urgent!

Hi, I´m need on this site, so please be patient :)

I have to finish this "game" for my final proyect on c++
Its a memory game that should display a map in which we need to match 2 words.

The thing is that when I try running it, an unexpected error apears.

I thinks it´s something with the strings and arrays, but I dont know.

Please I need help, I havent been able to solve this issue.

Could someone help me checking whats going on with my program?

Thank you!

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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
//Memorama
//*Pendiente
//* Visualizacion-DONE
//* desplegar el array/mapa ya con valores - DONE
//* cambiar numeros por palabras-PENDING
//* arreglar el primer display del array/mapa del memorama- DONE
//* arreglar el cout cuando se da un valor que ya esta desplegado- DONE
//* Ocultar el resultado del juego - DONE


	#include <iostream>
	#include <cstdlib>
	#include <ctime>
	#include <windows.h>
	
	using namespace std;
	void shuffle(int [][4]);

	int main()
{
	HANDLE outcon = GetStdHandle(STD_OUTPUT_HANDLE);//you don't have to call this function every time

    CONSOLE_FONT_INFOEX font;//utiliza window.h para establecer valores
    GetCurrentConsoleFontEx(outcon, false, &font);//PCONSOLE_FONT_INFOEX eslo mismo que CONSOLE_FONT_INFOEX*

    SetCurrentConsoleFontEx(outcon, false, &font);

	font.dwFontSize.X = 7;
    font.dwFontSize.Y = 12;
    SetConsoleTextAttribute(outcon, 0x10A);
    
    std::cout << "\t			Welcome to this memory game, developed by Robert Morales! \n\t		In the following game you have to type a number of column followed by a comma ,\n\t				 and then the number of the row!\n\n\n\t 					ENJOY THE GAME!!! :)\n\n\n\t 					Press enter to continue... ";
   std::cout <<  "\n\n\t\t\tDont forget to maximaze the screen and press enter before typing anything! \n\n\t\t\t\t\t\t\t GAME ON!";
   std::cin.get();
	
	
	
		char comma, ans = 'y'; //identificar el valor y coma
	    int r1, c1, r2, c2, cards[4][4], i(0); //establecer las opciones 
	    bool cardstatus[4][4];  // Array para guardar cuando una carta se volteada o no   
	    bool gameover = false;  //para saber si se acabo el juego
	    int moves;   

		    do
	  		  {
	        moves = 0;

	        

	       /*Desordenar Cartas*/   shuffle(cards); // Manejamos el array como desordenar
	       							system("cls");
 														
														for (int b=0; b<=0; b++)//Para no desplegar la solucion del juego
	               							 			cout<<endl;              //a menos que se busque en la parte superior del programa


	    	/*Desplegar el Array/mapa*/	        cout<<"\t    \t1 \t2 \t3 \t4\n ";

	        									cout<<"\t   "; //Acomodo de espacio

	       	for (int i=0; i<=3; i++)

	        {

	            cout<<"\t_";

	        }

	        cout<<endl;

	        for (int r=0; r<4; r++)

	        {

	            cout<<r+1<<"\t | ";

	            for (int c=0; c<4; c++)

	            {

	                cout<<"\t? ";

	                cardstatus[r][c] = false; // Usa 0 para falso y 1 para Verdadero

	            }

	            cout<<endl;

	        }

	        cout<<endl;

	        do // Empieza el juego y el jugador hace las modificaciones

	        {

	            do //seleccion

	            {

	               

	                cout<<"Please insert the first card row and column seperated by a comma.\n";

	                cin>>r1>>comma>>c1;

	                if(cardstatus[r1-1][c1-1] == true) // Ver si la carta se voltea

	                {

                    cout << "This card is already flipped! Select another card.";

	                }

	            }while(cardstatus[r1-1][c1-1]!= false);

		            do

	            {

	                cout<<"Please insert the second card row and column separated by a comma.\n";

	                cin>>r2>>comma>>c2;

	                if(cardstatus[r2-1][c2-1] == true) // Checar si la tarjeta se voltea

	                {

	                    cout << "This card is already flipped! Select another card.";

	                }

	                if((r1==r2)&&(c1==c2)) // si la carta seleccionada es la misma...

	                {

	                    cout << "You can't select same card twice!";

	                    continue;

	                }

	            }while(cardstatus[r2-1][c2-1]!= false);

	            //Arrelgo

	            r1--;

	            c1--;

	            r2--;

	            c2--;

	            //Mostrar

	            cout<<"\t   \t1 \t2 \t3 \t4\n";

	            cout<<"\t  ";

	            for (int i=0; i<=3; i++)

	            {

	                cout<<"\t_";

	            }

	            cout<<endl;

	            for (int r=0; r<4; r++)

	            {

	                cout<<r+1<<"\t | ";

	                for (int c=0; c<4; c++)

	                {

	                    if ((r==r1)&&(c==c1))

	                    {

	                        cout<<cards[r][c]<<"\t ";

	                    }

	                    else if((r==r2)&&(c==c2))

	                    {

	                        cout<<cards[r][c]<<"\t ";

	                    }

	                    else if (cardstatus[r][c] == true)

	                    {

	                        cout<<cards[r][c]<<"\t ";

	                    }

	                    else

	                    {

	                        cout<<"\t? ";

	                    }

	                }

	                cout<<endl;

	            }                       
	            cout << "Press enter to continue playing";

	            //Si coinsiden las cartas

	            if (cards[r1][c1]==cards[r2][c2]) // Mantenerlas volteadas

	            {

	                cout << "\nCards Matched!"<<endl;

	                 

	                cardstatus[r1][c1] = true;                            

	                cardstatus[r2][c2] = true;                           

	            }

	            cin.get();

	            cin.get();

	            //this pushes the next board onto a blank screen

	            for (int b=0; b<=20; b++)

	                cout<<endl;

	                 

	            for (int r=0; r<4; r++) // reprint the board, makes it easy for user to put a new guess.

	            {

	                cout<<r+1<<"\t | ";

	                for (int c=0; c<4; c++)

	                {               

	                    if (cardstatus[r][c] == true)

	                    {

	                        cout<<cards[r][c]<<"\t ";

	                    }

	                    else

	                    {

	                        cout<<"\t? ";

	                    }

	                }

	                cout<<endl;

	            }           

	            gameover = true;

	            for (int r=0; r<4; r++) // check all card status, they all should be true/flipped to end the game.

	            {

	                for (int c=0; c<4; c++)

	                {

	                    if(cardstatus[r][c]==false)

	                    {

	                      gameover = false;

	                      break;

	                    }

	                }

	                if(gameover == false)

	                {

	                    break;

	                }

	            }

	            moves++; // counting moves here.

	            //repeat

	        }while(gameover != true); // loop, the only way to get out is to finish the game!

	        cout << "Congratulations, You won!!!"<<endl;

	        cout << "It Required " << moves << " moves to finish it."<<endl<<endl;

	        cout << "Would you like to play again? (y=Yes/n=No) : ";

	        ans = cin.get();

	    }while(ans == 'y' || ans == 'Y'); // If user wants to play game again.

	    cin.get();

	    return 0;

	}

	void shuffle(int cards[][4])

	{

	  //  int start[16]={Hey,Sun,Luck,Rock,Key,Life,Bad,Dog,Hey,Sun,Luck,Rock,Key,Life,,8}; //MODIFICANDO
		 char *start[20]={"Hey","Sun","Luck","Rock","Key","Life","Bad","Dog","Hey","Sun","Luck","Rock","Key","Life","Bad","Dog"}; //MODIFICANDO
	    
		for (int s=0; s<=20; s++)

	    {

	        for (int x=0; x<16; x++)

	        {

	            srand((unsigned)time(NULL));

	            int i=rand()%15+1;

	            int temp=*start[x];

	            *start[x]=*start[i];

	            *start[i]=temp;

	        }

	    }   

	    int i=0;

	    for (int r=0; r<4; r++) // put values in cards here

	        {

	            for (int c=0; c<4; c++)

	            {

	                cards[r][c]=*start[i];

	                cout<<cards[r][c];               

	                i=i+1;

	            }

	            cout<<endl;

	        }

	}
Last edited on
Could you include the error message please?
Last edited on
Hi, the thing is that I dont reseave an error mesaje when running the program, I reseave a mesaje of windows stop working when the program is running.
In shuffle you attempt to modify the contents of string literals. Don't do that.
So what do I do?

I need to display on a map like this

1 2 3 4
______________________
1| ? ? ? ?
2| ? ? ? ?
3| ? ? ? ?
4| ? ? ? ?

Diferent words.

I used to use numbers, but I need to make a memory game with words.

It started when I added "*" to start on the code
It started when I added "*" to start on the code

Don't add stuff to the code that you don't understand.


1
2
3
4
5
6
7
8
  // If we have:
    char* literal1 = "word"; // literal1 points to the string literal "word"
    char* literal2 = "phrase";  // literal2 points to the string literal "phrase"
    // then:
    *literal1; // is the first character pointed to in the string literal, so

    *literal1 = *literal2; // is modifying (or attempting to modify) the string literal "word" which
                           // results in undefined behavior.  This is what you are doing in shuffle.   
Topic archived. No new replies allowed.