// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include #include #include #include using namespace std; int pickUp[50]; int dropOff[50]; int passengerCount[50]; float distanceTravelled[50]; float fareAmount[50]; float tollAmount[50]; float costPerMile[50]; double totalFare[50]; int numEntries; int ReadData(ifstream& file) { int t = -1; while (!file.eof()) { t++; file >> pickUp[t] >> dropOff[t] >> passengerCount[t] >> distanceTravelled[t] >> fareAmount[t] >> tollAmount[t]; totalFare[t] = fareAmount[t] + tollAmount[t]; if (distanceTravelled[t] != 0) { costPerMile[t] = fareAmount[t] / distanceTravelled[t]; } else costPerMile[t] = 0; } return t; } void GenerateTotals(int numEntries) { for (int i = 0; i < numEntries; i++) { cout << "Total fare for entry " << i + 1 << ": $" << totalFare[i] << endl; } int totalPassengers = 0; double totalPaid = 0; for (int i = 0; i < numEntries; i++) { totalPassengers += passengerCount[i]; totalPaid += totalFare[i]; } cout << "A total of " << totalPassengers << " passengers were transported." << endl; cout << "Altogether, the total amount paid was $" << totalPaid << endl; cout << "The average cost per person was $" << totalPaid / totalPassengers << endl; } int main() { ifstream inFile; string fileName; cout << fixed << setprecision(2); cout << "Please enter your data file name with the .txt extension:" << endl; cin >> fileName; inFile.open(fileName); if (inFile.is_open()) { cout << "Opened " << fileName << endl; } else { cout << "Failed to open " << fileName << endl; } int numEntries = ReadData(inFile); cout << "\nFound " << numEntries << " entries" << endl; GenerateTotals(numEntries); }