Random Game

Hi, i want you to give me a opinion about my game if you have time :)
It's the biggest, the hardest and the coolest of all games i made, i will appreciate some feedback.
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
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;

int main ()
{
	unsigned int RandomNumber1,RandomNumber2,RandomNumber3;		//Unsigned-Used when number is positive
	int Rules,MenuChoice,PlayerNumber,x,Dificulty;
	char WantPlay;
	string PlayerName[20];			//20 chars (to not waste memory)
	cout << "Want to play a game?y/n: ";
	cin >> WantPlay;
	getchar();
	switch(WantPlay)
	{
		case 'y':
			cout << "Good Luck";
			getchar();
			break;
		case 'Y':
			cout << "Good Luck";
			getchar();
			break;
		case 'n':
			goto exit;
			break;
		case 'N':
			goto exit;
			break;
	}
	cout << "MENU:\nPress 1 to read the rules;\nPress 2 to play;";
	cin >>	Rules;
	if (Rules==1)
	{
		cout << "RULES:\n1-Put a valid dificulty;\n2-Always input numbers;";
		cout << "\n3-Have fun!";
		getchar();
	}
	cout << "Enter your name: ";
	cin >> 	PlayerName[20];				//String w/ 20 chars max
	srand(unsigned(time(0)));		//Seed Random-Make the random number inspired in time (seconds)
	RandomNumber1 = rand()%10;		//0 to 9 (rand()%10+1 for 1 to 10)
	srand(unsigned(time(0)));
	RandomNumber2 = rand()%20;		//0 to 19
	srand(unsigned(time(0)));
	RandomNumber3 = rand()%100;		//0 to 99
	ReEnter:						//ReEnter Point
	restart:						//Restart
	getchar();
	cout << "Select the dificulty 0 to 2: ";
	cin >> Dificulty;
	if (Dificulty==0)				//GAME DIFICULTY 0
	{
		cout << "Press Enter to start the game.\n";
		getchar();
		for (x=0;x<10;x++)
		{
			getchar();
			cout << "Enter a number(0 to 9): ";
			cin >> PlayerNumber;
			if (PlayerNumber==RandomNumber1)		//Win statement
			{
				cout << "You Won!!";
				getchar();
				cout << "Congratulations " << PlayerName << "!";
				getchar();
				goto exit2;
			}
			else if (PlayerNumber!=RandomNumber1)
			{
				cout << "Keep trying";				//Wrong number statement
			}
			else if (x==9)
			{
				cout << "You Lost :'(";				//Lose statement
				getchar();
				goto exit2;
			}
			else
			{
				cout << "A number!";
			}
		}
	}
	else if (Dificulty==1)							//GAME DIFICULTY 1
	{
		cout << "Press Enter to start the game.\n";
		getchar();
		for (x=0;x<15;x++)
		{
			getchar();
			cout << "Enter a Number(0 to 19): ";
			cin >> PlayerNumber;
			if (PlayerNumber==RandomNumber2)
			{
				cout << "You Won!!";
				getchar();
				cout << "Congratulations " << PlayerName << "!";
				getchar();
				goto exit2;
			}
			else if (PlayerNumber!=RandomNumber2)
			{
				cout << "Keep trying";	
			}
			else if (x==14)
			{
				cout << "You Lost :'(";
				getchar();
				goto exit2;
			}
			else
			{
				cout << "A number!";
			}
		}
	}
	else if (Dificulty==2)							//GAME DIFICULTY 2
	{
		cout << "Press Enter to start the game.";
		getchar();
		for (x=0;x<20;x++)
		{
			getchar();
			cout << "Enter a number(0 to 99): ";
			cin >> PlayerNumber;
			if (PlayerNumber==RandomNumber3)
			{
				cout << "You Won!!";
				getchar();
				cout << "Congratulations " << PlayerName << "!";
				getchar();
				goto exit2;
			}
			else if (PlayerNumber!=RandomNumber3)
			{
				cout << "Keep trying";
			}
			else if (x==19)
			{
				cout << "You Lost :'( You should try dificulty 1.";
				getchar();
				goto exit2;
			}
			else
			{
				cout << "A number!";
			}
		}

	}
	else
	{
		cout << "Re-enter the dificulty.\n";
		getchar();
		goto ReEnter;
	}
	exit2:
	cout << "Press 1 to restart or 2 to Exit";
	cin >> MenuChoice;
	if (MenuChoice==1)
	{
		goto restart;
	}
	cout << "Thank's for playing :)\nGame by SkyDriver2500\n";
	getchar();
	exit:
	return 0;
}			
Whenever I put in my name, I get a message saying that It has stopped working.
cin >> PlayerName[20]; //String w/ 20 chars max

This extracts a single character from the standard input stream into the 21st element of PlayerName. PlayerName only has 20 elements.

cin.getline(Playername, 20) would be more appropriate. Your use of goto is ill-considered, and your monolithic main should be split into smaller functions.
Topic archived. No new replies allowed.