diff options
| author | tafaar <[email protected]> | 2022-11-28 19:56:00 -0800 |
|---|---|---|
| committer | tafaar <[email protected]> | 2022-11-28 19:56:00 -0800 |
| commit | af639ae820b892881fdd0807186a0888acc71f75 (patch) | |
| tree | d42040ae8344f2d9bd452163297c79dfad3b73c1 /BlankConsoleLab/BlankConsoleLab.cpp | |
| parent | Setting up GitHub Classroom Feedback (diff) | |
| download | cst116-lab3-hill-af639ae820b892881fdd0807186a0888acc71f75.tar.xz cst116-lab3-hill-af639ae820b892881fdd0807186a0888acc71f75.zip | |
first commit
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 78 |
1 files changed, 74 insertions, 4 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index ed5f807..28f2ddc 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -2,15 +2,85 @@ // #include <iostream> +#include <fstream> +#include <string> +#include <iomanip> using namespace std; -using std::cout; -using std::cin; -using std::endl; +int pickUp[50]; +int dropOff[50]; +int passengerCount[50]; + +float distanceTravelled[50]; +float fareAmount[50]; +float tollAmount[50]; +float costPerMile[50]; + +double totalFare[50]; + +void ReadData(ifstream file) { + +} int main() { - cout << "Hello World!\n"; + + 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 t = -1; + + while (!inFile.eof()) { + + t++; + + inFile >> 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; + + } + + cout << "Found " << t << " entries" << endl; + + for (int i = 0; i < t; i++) { + cout << "Total fare for entry " << i + 1 << ": $" << totalFare[i] << endl; + } + + int totalPassengers = 0; + double totalPaid = 0; + + for (int i = 0; i < t; 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; + } |