Constructor Problem, Displaying Blank

I think I might actually be doing this wrong. Is this allowed? when I try to display the choices, they are just blank. What is the proper way of setting values to the array airports?

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

class ORIGINANDDESTINATION
{
public:
	ORIGINANDDESTINATION()
	{
		string airports[34]= {"Bacolod", "Boracay", "Butuan", "Cagayan de Oro", "Calbayog", "Cataman", 
			"Cauayan", "Cebu", "Clark", "Coron(Busuanga)", "Cotabato", "Davao", "Dipolog", 
			"Dumaguete", "General Santos", "Iloilo", "Kalibo","Laoag", "Legazpi", "Manila",
			"Naga", "Ozamiz", "Pagadian", "PuertoPrincesa", "Roxas", "San Jose(Mindoro)",
			"Siargiao","Surigao", "Tacloban", "Tagbilaran", "Tawi-Tawi", "Tuguegarao",
			"Virac", "Zamboanga"};
	}
	void displayChoices()
	{
		cout << "||||||||||||||||||||||||||ORIGIN AND DESTINATION LIST|||||||||||||||||||||||||||\n";
		for (int i=0; i <34; i++)
		{
			if (i%2==1)
				cout << "[" << i+1 <<"]" << airports[i] << endl;
			else
				cout << "[" << i+1 <<"]" << left << setw(20) << airports[i];
		}
		cout << "\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
	}
	void getOrigin()
	{
		cout << "Please enter the the number of your origin and press enter: ";
		cin >> originChoice;		
		while (originChoice<1 || originChoice >34)
		{
			
			cout << "Invalid Input. Please enter choice origin again: ";
			cin >> originChoice;
		} 
	}
	void getDestination()
	{
		cout << "Please enter the the number of your destination and press enter: ";
		cin >> destinationChoice;
		while (destinationChoice<1 || destinationChoice >34)
		{
			cout << "Invalid input. Please enter destination choice again: ";
			cin >> destinationChoice;
		} 
	}
	void forDisplay(string& origin, string& destination)
	{
		origin=airports[originChoice-1];
		destination=airports[destinationChoice-1];

	}
private:
	string airports[34];
	int originChoice;
	int destinationChoice;	
};





Last edited on
Its the scope. You have a private airports in the class but in the constructor you declare another airports which hides the class airports. You need to not declare the airports in the constructor but just init it to the proper values.
Topic archived. No new replies allowed.