Hi everyone,
I am having trouble with this function.
What the function does is tell the user to input a city name. If the city name is found to output the results. If the city is not found to output "City not found". I got the function to work but the problem is that it repeats "City Not Found" 19 times. How would I modify the following code so it only outputs x amount that is in the .txt file being pulled from and only output once if the city is not found?
Thanks
I am having trouble with this function.
What the function does is tell the user to input a city name. If the city name is found to output the results. If the city is not found to output "City not found". I got the function to work but the problem is that it repeats "City Not Found" 19 times. How would I modify the following code so it only outputs x amount that is in the .txt file being pulled from and only output once if the city is not found?
Thanks
Rich (BB code):
void QueryCity(City Data[])
{
system("CLS");
cout << "Look up which city name: ? ";
string cityName;
cin >> cityName;
for (int i = 0; i < 20; i++)
{
if(Data.Name == cityName)
{
cout << "City Name: \t" << "# of Outages: \t" << "# of Total Customers: \t" << endl;
cout << Data.Name << "\t\t";
cout << Data.NumOfOutages << "\t\t";
cout << Data.TotalCust << "\t";
cout << endl;
}
else if (Data.Name != cityName)
{
cout << "City not found in the database" << endl;
}
}
system("PAUSE");
system("CLS");
}