Crashing and can't debug

Pleas help me with this, why is my code crashing?

It compiles then opens the exe then appcrash window comes up.

It says in the installer it's Dev C++ 5.9.2 but I look at the window it says 5.11 and I don't know wtf anymore.

I used other versions before and get the same problem.

I tried the debugger and shows a window that I have not enabled debugging info (-g) and when I click yes Dev C++ crashes.

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




#include<bits/stdc++.h>
#include<string>
#include<ctime>
#include<cstdlib>


using namespace std;

int main()
{
	srand(time(0));
	const string guess1="COMPUTING";
	const string guess2="INFORMATION";
	const string guess3="SCIENCE";
	int guess1len=guess1.length();
	int guess2len=guess2.length();
	int guess3len=guess3.length();
	string toguess;
	int guesspick=rand()%3;
	int toguesslength;
	toguesslength=toguess.length()-1;
	string wordhold[toguesslength+1];	
	int answer=0;
	int wrong=0;
	cout << toguesslength << endl;
	if (guesspick==0)
	{
		/*for(int h=1; h<=4; h++)
		{	
		guess1.replace(rand()%guess1len, 1 , "_");
		}*/
		toguess=guess1;
	}
	else if (guesspick==1)
	{
		/*for(int j=1; j<=4; j++)
		{
		guess2.replace(rand()%guess2len, 1 , "_");
		}*/
		toguess=guess2;
	}
	else if (guesspick==2)
	{
		/*for(int k=1; k<=4; k++)
		{
		guess3.replace(rand()%guess3len, 1 , "_");
		}*/
		toguess=guess3;
	}
	
	for (int x=0; x<=toguesslength; x++)
	{
		wordhold[x]=toguess.at(x);
	}
	
	for (int x=0; x<4; )
	{
		int blank=rand()%toguesslength;
		if (wordhold[blank]!="_")
		{
			wordhold[blank]="_";
			x++;
		}
	}
	
	cout<<"Word To Guess:";
	for (int x=0; x<=toguesslength; x++)
	{
		cout<<wordhold[x];
	}
	cout<<endl;
	
	
	char userguess;
	while (answer!=4 ||wrong!=3)
	{
		cout<<"Enter Guess:";
		cin>>userguess;
		
		for (int x=0; x<=toguesslength; x++)
		{
			if (userguess==toguess.at(x))
			{
				if (wordhold[x]=="_")
				{
					wordhold[x]=userguess;
					cout<<"Letter Matched"<<endl;
					answer++;
					break;
				}
			}
			else if (userguess!=toguess.at(x))
			{
				if (wordhold[x]=="_")
				{
					cout<<"No Match"<<endl;
					wrong++;
					break;
				}
				else continue;
			}
			
		}
			if (wrong==3)
			{
				cout<<"Game Over"<<endl;
				break;
			}
			else if (answer==4)
			{
				cout<<"Champion"<<endl;
				cout<<"You smart"<<endl;
				cout<<"I appreciate you"<<endl;
				break;
			}	else continue;
		}
		return 0;
	}
	



People said its the first instance of for (int x=0; x<=toguesslength; x++)
Hello Glaivetitan,

The problem occurs in the for loop at line 60.
It seems to be looping forever. Change it to for (int x=0; x<4; x++)

I hope this helps you, have a nice day:)

Best regards,

Mark.
Last edited on
By the way, I was looking at the rest of your code and I was wondering, can't you make an array with guesses and replace the lines 31 to 51 with something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
string guess [] = {"COMPUTING","INFORMATION","SCIENCE"};
int guesspick=rand()%3;

string guessString = guess[guesspick];
int guessStringLen = guessString.length();
string Replacedstring;
//string AllReplacedStrings
for(int h=1; h<=4; h++) // I don't know what you exactly want, but in this current code I rewrote for you, the forloop is kinda useless.
{	
	Replacedstring = guessString.replace(rand()%guessStringLen, 1 , "_");
	//AllReplacedStrings += Replacedstring
}
cout << Replacedstring<<endl;
//cout << AllReplacedStrings<<endl; 
Last edited on
I tried the debugger and shows a window that I have not enabled debugging info (-g) and when I click yes Dev C++ crashes.

Yes, there's a bug in that version of the IDE. If there's ever a newer version released it may be fixed.

Though there does seem to be some possible workaround, I don't recall exactly, but if you click 'no' instead of 'yes' it may work.
Topic archived. No new replies allowed.