diff options
| author | tafaar <[email protected]> | 2022-11-28 20:03:53 -0800 |
|---|---|---|
| committer | tafaar <[email protected]> | 2022-11-28 20:03:53 -0800 |
| commit | 8b9e2d64bd0ba670fab56ffefa99a571a2df31a6 (patch) | |
| tree | c0ae535146111b2ee294c1fc627092e9f5c50c85 | |
| parent | first commit (diff) | |
| download | cst116-lab3-hill-8b9e2d64bd0ba670fab56ffefa99a571a2df31a6.tar.xz cst116-lab3-hill-8b9e2d64bd0ba670fab56ffefa99a571a2df31a6.zip | |
added functions
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index 28f2ddc..75cb3c2 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -19,37 +19,17 @@ float costPerMile[50]; double totalFare[50]; -void ReadData(ifstream file) { +int numEntries; -} - -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 ReadData(ifstream& file) { int t = -1; - while (!inFile.eof()) { + while (!file.eof()) { t++; - inFile >> pickUp[t] >> dropOff[t] >> passengerCount[t] >> distanceTravelled[t] >> fareAmount[t] >> tollAmount[t]; + file >> pickUp[t] >> dropOff[t] >> passengerCount[t] >> distanceTravelled[t] >> fareAmount[t] >> tollAmount[t]; totalFare[t] = fareAmount[t] + tollAmount[t]; @@ -62,16 +42,20 @@ int main() } - cout << "Found " << t << " entries" << endl; + return t; + +} + +void GenerateTotals(int numEntries) { - for (int i = 0; i < t; i++) { + 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 < t; i++) { + for (int i = 0; i < numEntries; i++) { totalPassengers += passengerCount[i]; totalPaid += totalFare[i]; @@ -84,3 +68,33 @@ int main() } +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); + + + +} + |