C++ Problem Help

Hi I need help fixing my program. The last void function is where the issue occurs. I want it to allow the user to enter the city name and then output the corresponding zip code. It allows me to enter a city name but then does not show anything else. Can someone tell me what my error is?

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

//function prototypes
int displayMenu();
void displayInfo();
void addInfo();
void displayCity();
void displayZip();

int main()
{
int menuChoice = 0;

//display menu and get choice
menuChoice = displayMenu();

//call appropriate function or display error
while (menuChoice != 5)
{
if(menuChoice == 1)
addInfo();
else if(menuChoice == 2)
displayInfo();
else if(menuChoice == 3)
displayCity();
else if(menuChoice == 4)
displayZip();
else
cout << "Invalid choice" << endl;
//end ifs

//display menu and get choice
menuChoice = displayMenu();
}//end while

system("pause");
return 0;
} //end of main function

// Function definitions

int displayMenu()
{
//display a menu and then gets and returns users choice
int choice = 0;
cout << endl;
cout << "1. Add Information" << endl;
cout << "2. Display Information" << endl;
cout << "3. Display City" << endl;
cout << "4. Display Zip Code" << endl;
cout << "5. Exit Program" << endl;
cout << "Enter your choice: ";
cin >> choice;
cout << endl;
cin.ignore(100, '\n');
return choice;
}//end of displayMenu function

void displayInfo()
{
//displays the records stored in the zip.txt file
string zipCode = "";
string cityName = "";

//create file object and open the file
ifstream inFile;
inFile.open("Advanced26.txt", ios::in);

//determine whether the file was opened
if (inFile.is_open())
{
//read a record
getline(inFile, zipCode, '#');
getline(inFile, cityName);

while (!inFile.eof())
{
//display the record
cout << zipCode << " " <<
cityName << endl;
//read another record
getline(inFile, zipCode, '#');
getline(inFile, cityName);
} //end while

//close the file
inFile.close();
}
else
cout << "File could not be opened." << endl;
//end if
} //end of displayInfo function

void addInfo()
{
//writes records to a sequential access file
string city = "";
int zip = 0;

//create file object and open the file
ofstream outFile;
outFile.open("Advanced26.txt", ios::app);

//determine whether the file was opened
if (outFile.is_open())
{
//get the name of the city
cout << "Enter City Name (X to stop): ";
getline(cin, city);
while (city != "X" && city != "x")
{
//get the zip code
cout << "Enter the Zip Code: ";
cin >> zip;
cin.ignore(100, '\n');
//write the record
outFile << city << '#' << zip << endl;
//get another city
cout << "Enter City Name (X to stop): ";
getline(cin, city);
}//end while

//close the file
outFile.close();

}
else
cout << "File could not be opened" << endl;
//end if
}//end of addInfo function

void displayCity()
{
//reads records from a file and displays the City to the corresponding zip code entered by the user
string city = "";
int zip = 0;
int code = 0;

//create file object and open the file
ifstream inFile;
inFile.open("Advanced26.txt", ios::in);

//determine whether the file was opened
if (inFile.is_open())
{
//Get zip code from user
cout << "Enter the Zip Code: " << endl;
cin >> code;

//read a record
while(zip!=code)
{
getline(inFile, city, '#');
inFile >> zip;
}
}
if (code == zip)
{

inFile.close();

//display the City
cout << endl << city << endl;
cout << endl;
}
else
cout << "File could not be opened" << endl;
//end if
}

void displayZip()
{
//reads records from a file and displays the City to the corresponding zip code entered by the user
string city = "";
string zip = "";
string name = "";

//create file object and open the file
ifstream inFile;
inFile.open("Advanced26.txt", ios::in);

//determine whether the file was opened
if (inFile.is_open())
{
//Get zip code from user
cout << "Enter the City: " << endl;
cin >> name;

//read a record
while(city != name)
{
getline(inFile, zip, '#');
inFile >> city;
}
}
if (name == city)
{
inFile.close();

//display the City
cout << endl << zip << endl;
cout << endl;
}
else
cout << "File could not be opened" << endl;
//end if
}


It's so hard to read, I suggest using code tags.
http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.