Code:
...
// I don't think you need a string reference to store the
// city. I _believe_ that a copy is returned.
void getCity(string line, string& city)
// string getCity(string line) {
{
// If the city is one word, then the abbreviation will
// be the first and last letters of the word. Both letters
// should be capitalized. If the city is two words, then
// the abbreviation will be the first letter of each word.
// To temporarly store the city
string cityAbr = "";
string::size_type pos; // Bravo
pos = line.find(" "); //find the first space
// What if there is no space in the city name?
// Returns the position of the first occurrence in
// the string of the searched content.
//
// If the content is not found, the member value npos is returned.
// cityAbr = line.substr(0, 1); // First letter
// if (pos == string::npos) // City is one word
// cityAbr += line.substr(line.length() - 1, 1); // Last letter of city name
// else
// cityAbr += line.substr(pos + 1, 1); // First letter of second word
// std::transform(cityAbr.begin(), cityAbr.end(), cityAbr.begin(), toupper);
// return cityAbr;
// ???????? :o
if (line.at(pos + 1) >= '0' && line.at(pos + 1) <= '9') //will check the letter after the space...letter or number
cout << "My city is " << city << endl;
else
{
pos = line.find(" ", pos + 1); //find the second space in the city name
city = line.substr(0, pos); //gets both words
cout << "My city is " << city << endl;
}
}
tripType roundTrip()
{
// tripType is undefined
// Also, cout/cin and such should probably go
// into the main loop, and functions should
// just be doing work on that data
int x;
cout << "Please enter [1] for one-way or [2] for round trip ";
cin >> x;
// Undefined
return static_cast<tripType>(x);
}
int main()
{
ifstream fin;
int price = 0; // Monetary amounts are not integers
int salesTax = 0; // ---^
string line = "", city = ""; // Unused
bool upper = false; // Useless
fin.open("myinput.txt");
// Check for failure -- perhaps the file
// doesn't exist or something more tragic
// Broken
city = getCity(fin);
// Redundant
cout << "You have entered the city " << city;
return 0;
}