Run Errors

Sorry for the page stretch. OK my program is shutting down mid-program and giving me the errors below, How would I go about fixing it?

'projecttwo.exe': Loaded 'C:\Users\T_Dub\Documents\Visual Studio 2010\Projects\projecttwo\Debug\projecttwo.exe', Symbols loaded.
'projecttwo.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'projecttwo.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'projecttwo.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'projecttwo.exe': Loaded 'C:\ProgramData\Norton\{0C55C096-0F1D-4F28-AAA2-85EF591126E7}\N360_20.1.0.24\Definitions\BASHDefs\20130502.001\UMEngx86.dll', Cannot find or open the PDB file
'projecttwo.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'projecttwo.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
First-chance exception at 0x75464b32 in projecttwo.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0104f788..
Unhandled exception at 0x75464b32 in projecttwo.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0104f788..


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
  #include <fstream>
#include <string>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <iomanip>
using namespace std;

struct gamePiece {
  char horzLocation;
  int vertLocation;
  int validMoves;
  int invalidMoves;
} gamePieceLocation;

struct gamePieceMI {
  string direction;
  int numOfSpaces;
  ;
} moveInfo;

gamePiece gamePieceMover(gamePiece location, gamePieceMI moves);
void displayGameLocation(gamePiece displayLocation);
char isOccupied(gamePiece gpLocation, int horzLine, int vertLine);


int main()
{
	int moveAttempt = 0;
	string line;
	ifstream intData;
	string startPoint;
	intData.open("C:/Users/T_Dub/Desktop/data.txt");

	gamePieceLocation.horzLocation = 'A';
	gamePieceLocation.vertLocation = 5;
	gamePieceLocation.invalidMoves = 0;

	if(!intData)
	{
		cout<<"Error opening file, the program will close.\n\n";
		_getch();
		return 0;
	}

	while( !intData.eof() )
	{
		getline(intData, line);
        moveAttempt++;
	}
	intData.close();

	intData.open("C:/Users/T_Dub/Desktop/data.txt");
	while ( !( intData.eof() ) )
	{
		intData >> moveInfo.direction >> moveInfo.numOfSpaces;
		cout << "\n\n" << setw(25) << "Previous Location: " << gamePieceLocation.horzLocation << gamePieceLocation.vertLocation << endl;
		cout << setw(20) << "Direction: " << moveInfo.direction << "  " << moveInfo.numOfSpaces << endl << endl;
		gamePieceLocation = gamePieceMover(gamePieceLocation, moveInfo);
		cout << setw(9) << gamePieceLocation.validMoves << " Valid Moves Made" << endl;
		cout << setw(8) << gamePieceLocation.invalidMoves << " Invalid Moves Made" << endl << endl;
		displayGameLocation(gamePieceLocation);
		_getch();
	}

	getchar();
	intData.close();
	return 0;
}

gamePiece gamePieceMover(gamePiece location, gamePieceMI moves)
{	
	if ( ( !( (moves.direction.at(0) == 'L' && location.horzLocation - moves.numOfSpaces < 'A') || (moves.direction.at(0) == 'R' && location.horzLocation - moves.numOfSpaces > 'H') || (moves.direction.at(0) == 'U' && location.vertLocation + moves.numOfSpaces > 8) || (moves.direction.at(0) == 'D' && location.vertLocation - moves.numOfSpaces < 1) ) ) && ( (moves.direction.at(1) == 'L' && location.horzLocation - moves.numOfSpaces > 'A') || (moves.direction.at(1) == 'R' && location.horzLocation + moves.numOfSpaces < 'H' ) ) )
	{
		location.validMoves++;
		cout << setw(26) << "Movement was Valid" << endl;
	} else {
		location.invalidMoves++;
		cout << setw(27) << "Movement was Invalid" << endl;
	}

	if ( !( (moves.direction.at(0) == 'L' && location.horzLocation - moves.numOfSpaces < 'A') || (moves.direction.at(0) == 'R' && location.horzLocation - moves.numOfSpaces > 'H') || (moves.direction.at(0) == 'U' && location.vertLocation + moves.numOfSpaces > 8) || (moves.direction.at(0) == 'D' && location.vertLocation - moves.numOfSpaces < 1) ) )
	{
		if (moves.direction.length() == 2)
		{
			if ( (moves.direction.at(1) == 'L' && location.horzLocation - moves.numOfSpaces > 'A') || (moves.direction.at(1) == 'R' && location.horzLocation + moves.numOfSpaces < 'H' ) )
			{
				switch (moves.direction.at(1)) //Second
				{
				case 'L':
					location.horzLocation -= moves.numOfSpaces;
					break;
				
				case 'R':
					location.horzLocation += moves.numOfSpaces;
					break;
				
				default:
					cout << "critical error.";
				}
			} else {
				return location;
			}
		}
			
			switch (moves.direction.at(0)) //First
			{
			case 'U':
				location.vertLocation += moves.numOfSpaces;
				break;
			
			case 'D':
				location.vertLocation -= moves.numOfSpaces;
				break;
			
			case 'L':
				location.horzLocation -= moves.numOfSpaces;
				break;
			
			case 'R':
				location.horzLocation += moves.numOfSpaces;
				break;
			
			default:
				cout << "critical error.";
			}
		}
	return location;
}

void displayGameLocation(gamePiece displayLocation)
{
	int horzLine;
	int vertLine;

	cout << setw(28) << "The Gamepiece is now at: " << displayLocation.horzLocation << displayLocation.vertLocation << endl << endl;
	for (vertLine=8; vertLine>=1; vertLine--)
	{
		cout << vertLine << setw(4);
		
		for (horzLine=1;horzLine<=8; horzLine++)
		{
			cout << setw(4) << isOccupied(displayLocation, horzLine, vertLine);
		}
		
		cout<<endl;
	}
	cout << setw(5) << "A" << setw(4) << "B" << setw(4) << "C" << setw(4) << "D" << setw(4) << "E" << setw(4) << "F" << setw(4) << "G" << setw(4) << "H" << endl;
	return;
}

char isOccupied(gamePiece gpLocation, int horzLine, int vertLine)
{
	char occupied;
	

	if ( ( (gpLocation.horzLocation - 64) == horzLine) && (gpLocation.vertLocation == vertLine) )
	{
		occupied = 'X';
		return occupied;
	} else {
		occupied = '0';
		return occupied;
	}
}
Do you have a general idea of exactly when your program crashes?

It's throwing an exception that says you've used a value that is outside valid range:
output wrote:
Unhandled exception at 0x75464b32 in projecttwo.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0104f788..
The rest of the output is not errors.
It crashes the twelfth time going through while ( !( intData.eof() ) ) loop on line 56

After line 58:
cout << setw(20) << "Direction: " << moveInfo.direction << " " << moveInfo.numOfSpaces << endl << endl;

It displays
"Previous Location: E1
Direction: L 3 
and then it stops.
Last edited on
Then try looking at line 59. Before line 59 try printing out the values of the parameters you are passing to that function ;)
Huh? It was already displaying the values that was being sent. I added a cout for the move counters and it printed out two valid moves and 10 invalid. Same type of numbers being sent the first 12 times it goes through the loop. I don't see how that would mess something up but, then again I don't really understand the out_of_range error to begin with lol.

*EDIT* So, the error is at memory location 0x0104f788, right? I don't understand that number. How do I find it?
Last edited on
On line 73, are you sure that moves.direction.at(0) actually exists? What if there are no elements? If there are no elements, .at(0) will throw the out of bounds exception.
Isn't moves.direction.at(0) = 'L'? There is always a moves.direction.at(0) if I'm not mistaking.

*EDIT*
This is what being brought in from the text file up to that point. All the other one way directions went through fine.
UL	2
DL	5
UR	6
DL	7
DR	2
L	7
L	3
DR	2
DR	2
UR	4
DL	1
D	4
L	3
UR	5
Last edited on
Sorry, I meant moves.direction.at(1) - if the string is just "L" then there is no second character. I don't think you're using short-circuit evaluation properly.
Last edited on
No there is no character at moves.direction.at(1) but I have if (moves.direction.length() == 2) At Line 84 before I check for moves.direction.at(1). Does that not cover for it?

Short-circuit evaluation? I'm not sure what that is. Is there a page here that explains it? I just kind set up the if loops from scratch.
Last edited on
1
2
3
4
5
6
if ( ( !( (moves.direction.at(0) == 'L' && location.horzLocation - moves.numOfSpaces < 'A')
       || (moves.direction.at(0) == 'R' && location.horzLocation - moves.numOfSpaces > 'H')
       || (moves.direction.at(0) == 'U' && location.vertLocation + moves.numOfSpaces > 8)
       || (moves.direction.at(0) == 'D' && location.vertLocation - moves.numOfSpaces < 1) ) )
     && ( (moves.direction.at(1) == 'L' && location.horzLocation - moves.numOfSpaces > 'A')
       || (moves.direction.at(1) == 'R' && location.horzLocation + moves.numOfSpaces < 'H' ) ) )
In this case, your code is required to check moves.direction.at(1) even if the string only has 1 character in it.
Ahh! I see but I need it to check both of them together. Or can I put a preliminary check and separate them?

Would something like this work?
1
2
3
4
5
6
7
8
9
10
if One{
Valid = Movement Valid
Invalid = Movement Invalid
}

if Two{
Both Valid = Movement Valid
One Invalid, One Valid = Movement Invalid
Two Invalid= Movement Invalid
}


*EDIT* Worked perfectly! Thanks!
Last edited on
Topic archived. No new replies allowed.