Program Struct Of Addresses Call Array Into Function

Hello everyone,

Beginner C++ student here starting to learn different ways of using arrays and a bit of structs. Studying how these work together and I am trying to put together the program below. One function is to just return all the struct data, the second set of functions is to return the addresses with the specified zipcode in the function, and the third set of functions (last two in the code) is suppose to return the addresses only with the zipcodes listed in the array desiredZip[91371, 91375].

However, I am having a difficult time trying to call that array into those two last functions.

What would be the best way to have the functions look at the array and return only those the addresses with those two zipcodes?

Right now it returns all data from the struct.

Thank you so very much for any and all help. 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
 



#include <iostream>
#include <string>
using namespace std;


struct Address {

	unsigned number;
	string street;
	string suffix;
	string city;
	string state;
	unsigned zip;

};

bool die(const string & address);

void show(const Address & emp);

void show(Address address[], unsigned elements, double desiredZip);
void show(Address & address, double desiredZip);

void show(const Address address[], unsigned addressElements, 
	const unsigned desiredZip[], unsigned desiredZipElements);
void show(const Address & address, double desiredZip);


int main() {

	const unsigned SIZE = 6;
	unsigned desiredZip[SIZE];

	Address a[SIZE] {

		{ 6401, "Winnetka", "Ave", "Woodland Hills", "CA", 91371 },
		{ 4792, "Ventura", "Ave", "Woodland Hills", "CA", 91371 },
		{ 2001, "Porter", "Ave", "Woodland Hills", "CA", 91371 },
		{ 1234, "Victory", "Ave", "Calabasas", "CA", 91375 },
		{ 992, "Shoup", "Ave", "Chatsworth ", "CA", 91375 },
		{ 992, "Shoup", "Ave", "Chatsworth ", "CA", 91376 }


	};


	for (unsigned i = 0; i < SIZE; i++)
		show(a[i]);
	cout << endl;


	for (unsigned i = 0; i < SIZE; i++)
		show(a[i], SIZE);
	cout << endl;

	
	desiredZip[91371, 91375];

	for (unsigned i = 0; i < SIZE; i++)
		show(a[i]);
	cout << endl;

	



} // main




bool die(const string & msg) {
	cout << "Fatal error: " << msg << endl;
	exit(EXIT_FAILURE);
}




void show(const Address & address) {
	cout << address.number << " " << address.street << " " << address.suffix << "  " << endl;
	cout << address.city << " " << address.state << " " << address.zip << endl;
}


void show(Address address[], unsigned elements, double desiredZip) {
	

	
	for (unsigned i = 0; i < elements; i++)

		show(address[i], desiredZip);

}



void show(Address & address, double desiredZip) {
		
	while (address.zip == 91371) {

		show(address);

		break;

	}
}





void show(const Address address[], unsigned addressElements, 
	const unsigned desiredZip[], unsigned desiredZipElements) {

	for (unsigned i = 0; i < addressElements; i++)
		show(address[i], desiredZip[i]);

}

void show(const Address & address, double desiredZip) {


		while (address.zip == desiredZip) {

			show(address);

			break;

	}
}

Topic archived. No new replies allowed.