open stackdump file error message

Hi all,

I am relatively new to c++ and entirely new to forums in general, so forgive any mistakes I might make in the wording of my post.

I have been getting this error message:

0 [main] MagicSquare 1416 cygwin_exception::open_stackdumpfile: Dumping stack trace to MagicSquare.exe.stackdump

whenever I include the loop structure to cycle through the functions rule1(vector<int>magicSq), rule2(vector<int>magicSq), and rule3(vector<int>magicSq).

I have tried using for, do-while, and while loops to no avail. I have also tried placing the control structure in the display() function but that did not work either. The code works fine without the loop, but it does not complete the magic square that I need to create.

Any insight would be greatly 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

#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

class Square {
public:
	Square(int n);
	Square();
	void display();
	void firstNumber(vector<int>& magicSq);
	void rule1(vector<int>& magicSq);
	void rule2(vector<int>& magicSq);
	void rule3(vector<int>& magicSq);
	void print(vector<int>& magicSq);

private:
	int number, entryNumber, index, temp;
	int indexBegin;
	int indexEnd;

};

Square::Square(int n) {//Constructor initializes default values as well as an argument for number
	number = n;
	entryNumber = 1;
	index = 0;
	indexBegin = number / 2;
	indexEnd = pow(number, 2);
	temp = indexBegin; //Sets temp equal to the index number of insertion
}

Square::Square() {//Default constructor
	number = 3;
	entryNumber = 1;
	index = 0;
	indexBegin = number / 2;
	indexEnd = pow(number, 2);
	temp = indexBegin;
}

int main() {
	Square magic(5);
	magic.display();

	return 0;

}

void Square::display() {

	//Creates a vector the size of the number squared

	vector<int> magicSq;

	for (int i = 0; i < indexEnd; i++) {
		magicSq.push_back(i);
	}

	firstNumber(magicSq);
	rule1(magicSq);

	cout << "The size of your square is: ";
	cout << magicSq.size() << endl;

	print(magicSq);

}

void Square::firstNumber(vector<int>& magicSq) {

	//Inputs the first number

	magicSq.erase(magicSq.begin() + indexBegin);

	magicSq.insert(magicSq.begin() + indexBegin, entryNumber);

	entryNumber++; //Increments, meaning next number input is 2

}

void Square::rule1(vector<int>& magicSq) {
while (entryNumber <= indexEnd){

	/*The first rule states that if the index minus the number is less than
	 * zero, then the number must be inserted at an index greater than the 
	 * original by adding the number multiplied by the number minus one to                                       *          one.
	 */

		if ((temp - number) < 0) {

			temp = magicSq.at(temp + (number * (number - 1) + 1));

			magicSq.erase(magicSq.begin() + temp);

			magicSq.insert(magicSq.begin() + temp, entryNumber);

			entryNumber++;
		}

		rule2(magicSq);
		rule3(magicSq);
	}
}

void Square::rule2(vector<int>& magicSq) {

	/*Second rule of the magic square. If the index minus the number is greater than zero,
	 * then the number must be inserted at the original index minus the number minus one.
	 */

	if ((temp - number) >= 0) {

		temp = magicSq.at(temp - (number - 1));

		magicSq.erase(magicSq.begin() + temp);

		magicSq.insert(magicSq.begin() + temp, entryNumber);

		entryNumber++;
	}

}

void Square::rule3(vector<int>& magicSq) {

	/*Third rule for the magic square.  If the index number minus the number minus one is
	 * equal to a multiple of the original number, then the number must be placed at an
	 * index equal to the number times two minus one.*/


	int checkLeft = temp - (number - 1);

	for (int i = 1; i <= number; i++) {
		if (checkLeft == number * i) {
			temp = magicSq.at(temp - ((number * 2) - 1));

			magicSq.erase(magicSq.begin() + temp);

			magicSq.insert(magicSq.begin() + temp, entryNumber);

			entryNumber++;
		}
	}

}

void Square::print(vector<int>& magicSq) {

	//Print function to output the square

	int i = 0;

	for (int a = 0; a <= number; a++) {
		for (i; i < (number * a); i++) {
			cout << magicSq[i];
			cout << " ";
		}
		cout << endl;
	}
}
Topic archived. No new replies allowed.