OK I have a txt file that appears like so
Tacoma Tacoma 0
Tacoma Seattle 15
Tacoma Spokane 24
I have it declared as such
inFile >> city1 >> city2 >> dist
My question is what do I need to do to have my program match my two cin locations to the txt file to get the correct integer on the third column. As an example my first cin location was Tacoma and my second cin location was Spokane, my result should have been 24 when I coded in outFile << dist but I keep getting 0 as a result.
Is there an example for this. I do not need someone writing my code for me but an example of how to get this to work would help me understand what I have been doing wrong.
int client()
{
string city1;
string city2;
int distance;
bool city1found = false;
bool city2found = false;
ifstream inClient;
ifstream inDist;
ifstream inroute;
ofstream outClient;
ofstream outDist;
inClient.open("client.txt", ios::app);
inDist.open("post.txt", ios::app);
outClient.open("client.txt", ios::app);
outDist.open("post.txt", ios::app);
inroute.open("routes.txt");
inroute >> city1;
inroute >> city2;
inroute >> distance;
cout << "Business Name (First & Last Name): ";
cin >> cFirst >> cLast;
outClient << cFirst << " " << cLast;
outDist << cFirst << " " << cLast;
cout << "Origin of delivery: ";
cin >> clocation;
if (clocation == city1) //if the current city is equal to the inputted from city
{
city1found = true;
}
else if (city1found == false)
{
cout << endl << "Origin city not found." << endl;
cin >> clocation;
}
outClient << "\t\t" << clocation;
outDist << setw(15) << clocation;
cout << "Seven digit phone number (EX. 671-689-5134): ";
cin >> cphone;
outClient << "\t\t" << cphone;
cout << "Email address: ";
cin >> cemail;
outClient << "\t\t" << cemail;
cout << "Destination of delivery: ";
cin >> cdestination;
if (cdestination == city2) //if the current city is equal to the inputted from city
{
city2found = true;
}
else if (city2found == false)
{
cout << endl << "Detination not found." << endl;
cin >> cdestination;
}
outClient << "\t\t" << cdestination;
outDist << setw(15) << cdestination;
cout << "Weight of Shipment(Tons): ";
cin >> weight;
outClient << "\t\t" << weight;
outDist << setw(15) << weight;
//Distance established
if (inroute.is_open())
{
while (!inroute.eof())
{
if (clocation && cdestination == city1 && city2)
{
distance;
}
}
}
outClient << "\t\t" << distance;
outDist << setw(15) << distance;
outClient << endl;
outDist << endl;
cout << "Order confirmed" << endl;
cout << "Enter '0' to return to the Main Menu or '1' to exit out of program" << endl;
cin >> ans;
if (ans == 0)
{
system("CLS");
main();
}
else (ans == 1);
{
exit(0);
}
}