Program goes into infinite loop, showing weird characters

After I successfully read in and stored my datas. When I press 2 to change my filtering criteria, changing it to a, b or c it is fine and working but whenever I chooses 'd'. It goes into this mad infinite loop showing weird characters and then hangs.

Here is my code
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
//all other stuff;
class Assn3
{ 
    private:
             
    int FC;
    int SC;
    int SO;
//vectors
    public:
   	Assn3();
   	void mainMenu(); 
   	void inputFile();
   	void viewData();
   	void outputFile();
   	
    char FM();
    string getFC();
   	void setFC();
   	void processFilter(char choice);
    void point2D();
	void point3D();
	void line2D();
	void line3D();
   	
	char SM();
	string getSC();
	void setSC();
	void processSorting(char choice);
	void pt1();
	void pt2();
	void length();
	
	char SOM();
	string getSO();
	void setSO();
	void processSortingorder(char choice);
	void asc();
	void dsc();
};

Assn3::Assn3()
{
	FC = 1;
	SC = 1;
	SO = 1;
}

//main menu
void Assn3::mainMenu()
{
    cout<<"1) Read in data."<<endl;
    cout<<"2) Specify filtering criteria (current: "<<getFC()<<")"<<endl;
    cout<<"3) Specify sorting criteria (current : "<<getSC()<<")"<<endl;
    cout<<"4) Specify sorting order (current: "<<getSO()<<")"<<endl;
    cout<<"5) View Data"<<endl;
    cout<<"6) Store Data"<<endl;

	cout<<"Please enter  : ";
}

//filter menu
char Assn3::FM()
{
    char o;
	cout<<"[ Specifying filtering criteria (current : "<<getFC()<<") ]"<<endl<<endl;
	cout<<"a) Point2D "<<endl;
	cout<<"b) Point3D "<<endl;
	cout<<"c) Line2D "<<endl;
	cout<<"d) Line3D  "<<endl<<endl;
	cout<<"Please enter  (a - d) : ";
	cin>>o;

	return o;
}

//sort menu
char Assn3::SM()
{
	char o;
	switch(FC)
	{
	case 1:
		cout<<"[ Specifying sorting criteria (current : "<<getSC()<<") ]"<<endl<<endl;
		cout<<"a)	ordinate Value "<< endl;
		cout<<"b)	ordinate Value "<< endl;
		cout<<"c)	st. Fr Origin Value "<< endl<<endl;
		cout<<"Please enter  (a - c) : ";
		cin>>o;
		break;
	case 2:
		cout<<"[ Specifying sorting criteria (current : "<<getSC()<<") ]"<<endl<<endl;
		cout<<"a) X Value "<<endl;
		cout<<"b) Y Value "<<endl;
		cout<<"c) Z Value "<<endl;
		cout<<"d) Dist. Value "<<endl<<endl;
		cout<<"Please enter  (a - d) : ";
		cin>>o;
		break;
	case 3:
		cout<<"[ Specifying sorting criteria (current : "<<getSC()<<") ]"<<endl<<endl;
		cout<<"a) Pt. 1 values "<< endl;
		cout<<"b) Pt. 2 values "<< endl;
		cout<<"c) Length value "<<endl<<endl;
		cout<<"Please enter  (a - c) : ";
		cin>>o;
		break;
	}
	return o;	 
}

//sort order menu
char Assn3::SOM()
{
    char o;
	cout<<"[ Specifying sortin order (current : "<<getSO()<< ") ]"<<endl<<endl;
	cout<<"a)ASC  "<<endl;
	cout<<"b)DSC  "<<endl<<endl;
	cout<<"Please enter  (a - b) : ";
	cin>>o;

	return o;

	cout << "Sorting set to '" << getSO() << "'!" << endl;
}
//for filter criteria
string Assn3::getFC()
{
	switch(FC)
	{
	case 1:
		return "Point2D";
		break;
	case 2:
		return "Point3D";
		break;
	case 3:
		return "Line2D";
		break;
	case 4:
		return "Line3D";
		break;
	}
}

//for filter criteria
void Assn3::setFC()
{
	char o;
	o = FM();
	processFilter(o);

	cout << "Filter criteria  set to '" << getFC() << "'!" << endl;
}

void Assn3::point2D()
{
	FC = 1;
}

void Assn3::point3D()
{
	FC = 2;
}

void Assn3::line2D()
{
	FC = 3;
}

void Assn3::line3D()
{
	FC = 4;
}
void Assn3::processFilter(char choice)
{
	switch(choice) 
	{
	case 'a' :
		point2D();
		break;
	case 'b' :
		point3D();
		break;
	case 'c' :
		line2D();
		break;
	case 'd' :
		line3D();
		break;
	}
}

string Assn3::getSC()
{
	switch(FC)
	{
	case 1:
		switch(SC)
		{
		case 1:
			return "X-ordinate";
		case 2:
			return "Y-ordinate";
		case 3:
			return "Dist. Fr Origin Value";
		}
		break;
	case 2:
		switch(SC)
		{
		case 1:
			return "X-ordinate";
		case 2:
			return "Y-ordinate";
		case 3:
			return "Dist. Fr Origin Value";
		}
		break;
	case 3: 
		switch(SC)
		{
		case 1:
			return "Pt. 1's (x, y)";

		case 2:
			return "Pt. 2's (x, y) values";

		case 3:
			return "Length value";
		}
		break;
	}
}

void Assn3::setSC()
{
	char o;
	o = SM();
	processSorting(o);

}

void Assn3::pt1()
{
	SC = 1;
}

void Assn3::pt2()
{
	SC = 2;
}

void Assn3::length()
{
	SC = 3;
}

void Assn3::processSorting(char choice)
{
	switch(choice) 
	{
	case 'a' :
		pt1();
		break;
	case 'b' :
		pt2();
		break;
	case 'c' :
		length();
		break;
	}
}

string Assn3::getSO()
{
	switch(SO)
	{
	case 1:
		return "ASC";
		break;
	case 2:
		return "DSC";
		break;	  	  
	}
}

void Assn3::setSO()
{
	char o;
	o = SOM();
	processSortingorder(o);
	cout << "Filter criteria  set to '" << getSO() << "'!" << endl;
}

void Assn3::asc()
{
	SO = 1;
}

void Assn3::dsc()
{
	SO = 2;
}

void Assn3::processSortingorder(char choice)
{
	switch(choice) 
	{
	case 'a' :
		asc();
		break;

	case 'b' :
		dsc();
		break;
	}
}

void Assn3::inputFile()
{
     ifstream openfile;
     string getcontent;	
     int count = 0;
     
     cout<<endl;
     cout<<"Please enter filename : ";
     cin>>getcontent;
     openfile.open(getcontent.c_str());
     if (openfile.fail())
     {
      cerr<<"Error with file:" <<getcontent.c_str()<<endl;
      return;
     }
     while (openfile.good())
     {     
           string line;
           openfile>>line;
           	 
           if(line == "Point2D,")
           {	
             Point2D p2d;
             openfile >> p2d; 
             p2ds.push_back(p2d); 
             count++;
             p2ds.erase( unique( p2ds.begin(), p2ds.end()), p2ds.end());  	     	 	 
            }
            else if (line == "Point3D,")
		    {
			     Point3D p3d;
			     openfile >> p3d; 
                 p3ds.push_back(p3d); 
			     count++;
                 p3ds.erase( unique( p3ds.begin(), p3ds.end()), p3ds.end());  	 
		    } 
            else if (line == "Line2D,")
		    {
			     Line2D l2d;
			     openfile >> l2d;
			     l2ds.push_back(l2d); 
			     count++;
                 l2ds.erase( unique( l2ds.begin(), l2ds.end()), l2ds.end());  
		    }
            else if (line == "Line3D,")
		    {
			     Line3D l3d;
			     openfile >> l3d;
			     l3ds.push_back(l3d); 
			     count++;
                 l3ds.erase( unique( l3ds.begin(), l3ds.end()), l3ds.end()); 
		   }       	
      }
      openfile.close();
}

void Assn3::viewData()
{
       cout<<"[ View data ... ]"<< endl;
       cout<<"filtering criteria : " <<getFC() << endl;
       cout<<"sorting criteria : " <<getSC() << endl;
       cout<<"sorting order : " <<getSO() << endl;
       switch(FC)
       {
       case 1:
 			//show all Point2D datas
      	    cout<<" X  Y  Dist. Fr Origin"<<endl;
            for(int i = 0; i < p2ds.size(); i++)
            {
	        	cout<<p2ds[i]<<"\t"<<setprecision(3)<<p2ds[i].getScalarValue()<<endl;
            }
            break;   
       case 2:
			//show all Point3D datas
			cout<<" X  Y  Z  Dist. Fr Origin"<<endl;
 
			for(int i = 0; i < p3ds.size(); i++)
			{
				cout<<p3ds[i]<<"\t"<< setprecision(3)<<p3ds[i].getScalarValue()<<endl;
			}
			break;
	   case 3:
	   		//show all line2d datas
			cout<<" P1-X  P1-Y  P2-X  P2-Y  Length"<<endl;
 
			for(int i = 0; i < l2ds.size(); i++)
			{
				cout << l2ds[i] << endl;
			}
			break;
	  case 4:
			cout<<" P1-X  P1-Y  P1-Z  P2-X  P2-Y  P2-Z  Length"<<endl;
 
			for(int i = 0; i < l3ds.size(); i++)
			{
				cout << l3ds[i] << endl;
			}
			break;
       }
}

int main()
{
    Assn3 assn3;
 	int choice; 
    bool exit;
	const int END = 999;

	while (choice != END)
	{
        assn3.mainMenu();
        cin>>choice;
        
	 	switch(choice)
		{
			case 1:
			{
                assn3.inputFile();
			}
			break;
			case 2 :
           	{
                assn3.setFC();
			}
            break;
		  	case 3 :
			{
  	          	assn3.setSC();
            }
            break;
			case 4:
			{
               	assn3.setSO();	  
			}
            break;
			case 5:
			{
              	assn3.viewData();
			}
            break;
			case 6:
			{
              	assn3.outputFile();
			}
			break;
		default:
			{
				cout<<"Invalid entry"<<endl<<endl;	   
			}
			break;           
		}
	}	 	 return 0;
}
#endif 
Anyone can help? Whenever I press 2 to select the filter criteria and change it to 'd', the program will hang straight away
Have you tried debugging the program to see where it is when it is hanging?
I didn't. How do I start debugging? I am using quincy 2005
Topic archived. No new replies allowed.