diff options
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 82 |
1 files changed, 59 insertions, 23 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index 1a2c811..0db9226 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -62,7 +62,7 @@ void GenerateTotals(int numEntries) { cout << "TOTAL PASSENGERS: " << totalPassengers << endl; cout << "TOTAL PAID: $" << totalPaid << endl; - cout << "COST PER PERSON: $" << totalPaid / totalPassengers << endl; + cout << "AVG COST PER PERSON: $" << totalPaid / totalPassengers << endl; cout << "TOTAL TRIPS: " << numEntries << endl; } @@ -74,36 +74,72 @@ int main() string fileName; cout << fixed << setprecision(2); + char choice = 'Y'; - cout << "Please enter your data file name with the .txt extension:" << endl; - cin >> fileName; + while (choice == 'Y') { - inFile.open(fileName); + while (!inFile.is_open()) { - if (inFile.is_open()) { - cout << "Opened " << fileName << endl; - } - else { - cout << "Failed to open " << fileName << endl; - } + cout << "Please enter your data file name with the .txt extension:" << endl; + cin >> fileName; + + inFile.open(fileName); + + if (inFile.is_open()) { + cout << "\nOpened " << fileName << endl; + } + else { + cout << "\nFailed to open " << fileName << endl; + } + + cout << endl; + + } + + int numEntries = ReadData(inFile); + + GenerateTotals(numEntries); + + choice = 'A'; + + while (choice != 'Y' && choice != 'N') { - int numEntries = ReadData(inFile); + cout << "\nWould you like to display a table? Y/N" << endl; + cin >> choice; - GenerateTotals(numEntries); + } + + if (choice == 'Y') { + + cout << left << setw(10) << "\nENTRY" << setw(10) << "PICKUP" + << setw(10) << "DROPOFF" << setw(10) << "#PASS" + << setw(10) << "DIST" << setw(10) << "FARE$" + << setw(10) << "TOLL$" << setw(10) << "TOTAL$" + << setw(10) << "$/MILE" << endl; - cout << left << setw(15) << "PICKUP ST." - << setw(15) << "DROPOFF ST." << setw(15) << "# PASSENGERS" - << setw(15) << "DISTANCE" << setw(15) << "FARE" - << setw(15) << "TOLL" << setw(15) << "TOTAL" - << setw(15) << "$/MILE" << endl; + for (int i = 0; i < numEntries; i++) { + + cout << left << setw(10) << i + 1 << setw(10) << pickUp[i] + << setw(10) << dropOff[i] << setw(10) << passengerCount[i] + << setw(10) << distanceTravelled[i] << setw(10) << fareAmount[i] + << setw(10) << tollAmount[i] << setw(10) << totalFare[i] + << setw(10) << costPerMile[i] << endl; + + } + } + + choice = 'A'; + + while (choice != 'Y' && choice != 'N') { + + cout << "\nWould you like to open another file? Y/N" << endl; + cin >> choice; + + } - for (int i = 0; i < numEntries; i++) { + inFile.close(); - cout << left << setw(15) << pickUp[i] - << setw(15) << dropOff[i] << setw(15) << passengerCount[i] - << setw(15) << distanceTravelled[i] << setw(15) << fareAmount[i] - << setw(15) << tollAmount[i] << setw(15) << totalFare[i] - << setw(15) << costPerMile[i] << endl; + cout << endl; } |