// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include #include #include #include using std::cout; using std::cin; using namespace std; int PickUp[50]; int DropOff[50]; int Passenger[50]; float Distance[50]; float Fare[50]; float Toll[50]; float CPM[50]; //cost per minute double TotalCost[50]; int NumberEntries; int ReadData(ifstream& file) { int f = -1; //f is the number of entries while (!file.eof()) { f++; file >> PickUp[f] >> DropOff[f] >> Passenger[f] >> Distance[f] >> Fare[f] >> Toll[f]; TotalCost[f] = Fare[f] + Toll[f]; if (Distance[f] != 0) { CPM[f] = Fare[f] / Distance[f]; } else CPM[f] = 0; } f++; return f; } void GenerateTotals(int NumberEntries) { int PassengersTotal = 0; double TotalPaid = 0; for (int i = 0; i <= NumberEntries; i++) { PassengersTotal += Passenger[i]; TotalPaid += TotalCost[i]; } cout << "Total passenger count ->> " << PassengersTotal << endl; cout << "Total paid ->> " << TotalPaid << endl; cout << "The average cost per person is ->> $" << TotalPaid / PassengersTotal << endl; cout << "Total trips ->> " << NumberEntries << endl; } int main() { ifstream inFile; string fileName; cout << fixed << setprecision(2); while (!inFile.is_open()) { cout << "Enter your file name with .txt extension ->>" << endl; cin >> fileName; inFile.open(fileName); if (inFile.is_open()) { cout << "\nOpened " << fileName << endl; } else { cout << "\nCould not open " << fileName << endl; } cout << endl; } int NumberEntries = ReadData(inFile); GenerateTotals(NumberEntries); }