zip city

cant get it to where i type in zip it just skips it

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

    int displayMenu ();
	void addRecords ();
	void zip ();
	void city ();
	void display();

int main()
{
	int choice=0;

	while(choice != -1)
	{
		switch(choice)
		{
		case 1:
			{
				addRecords();
				break;
			}
		case 2:
			{
				city();
				break;
			}
		case 3:
			{
				zip();
				break;
			}
		case 4:
			{
				display();
				break;
			}
		default:
			cout << "Invalid choice" <<endl;
		}
		choice = displayMenu();
	}

	system("pasue");
	return 0;
}

int displayMenu()
{
	int choice1 = 0;
	cout << endl << "Menu" << endl;
	cout << "1 add new city and new zip"<<endl;
	cout << "2 search for city by zip" << endl;
	cout << "3 search for zip by city"<< endl;
	cout << "4 Display file contents"<< endl;
	cout << "-1 to exit program" << endl;
	cout << "Enter menu choice: ";
	cin >> choice1;
	cout << endl;
	return choice1;
}

void addRecords()
{
	string city="";
	string zip="";
	ofstream outFile;

	outFile.open("zipcity.txt", ios::app);
	if(outFile.is_open())
	{
		cout<<"Enter City Name: ";
		cin.ignore(1);
		getline(cin, city);
		outFile<<city<<"#";

		cout << "enter zip code: ";
		cin>> zip;
		outFile<<zip<<endl;

		outFile.close();
	}
	else
		cout<<"File could not be opened please contact tech support..."<<endl;
}

void city()
{
	ifstream inFile;
	int x =0;
	string zip1="";
	string search="";
	bool found = false;

	inFile.open("zipcity.txt", ios::app);
	if(inFile.is_open())
	{
		cout<<"Enter zip: "<< zip1 << endl;
		while(found == false && inFile.eof() == false)
		{
			getline(inFile, search);

			if(search.find(zip1) != -1)
			{
				found = true;
				x=search.find("#", 0);
				search.erase(x);
				cout<<"City for Zip" << zip1 << " is: "<< search<< endl;
			}
		}

		inFile.close();
		if(found == false)
			cout<<"No city found for that zip."<<endl;
	}
	else
		cout<<"File could not be opened please contact tech support..."<<endl;
}

void zip()
{
	ifstream inFile;
	string city1 ="";
	string search1="";
	bool found1 = false;
	
	inFile.open("zipcity.txt", ios::app);
		if(inFile.is_open())
		{
			cout<<"enter city please: ";
			cin.ignore(1);
			getline(cin, city1);
			transform(city1.begin(), city1.end(), city1.begin(), tolower);

			while(found1 == false && inFile.eof() == false)
			{
				getline(inFile, search1);
				transform(search1.begin(), search1.end(), search1.begin(), tolower);

				if(search1.find(city1) != -1)
				{
					found1 = true;
					search1.erase(search1.find(city1), city1.length() +1);
					cout<< "zip for "<< city1 << " is: "<< search1<< endl;
				}
			}
			inFile.close();

			if(found1 == false)
				cout<<"no zip was found for that city please contact tech support..."<< endl;
		}
		else
			cout<<"file could not be opened if you need help contact tech support..."<<endl;
}

void display()
{
	ifstream inFile;
	string line="";

	inFile.open("zipcity.txt", ios::app);
	if(inFile.is_open())
	{
		while(inFile.eof() == false)
		{
			getline(inFile, line);
			cout <<line<< endl;
		}

		inFile.close();
	}
	else
		cout<< "file could not be opened please contact tech support..." << endl;
}
Topic archived. No new replies allowed.