summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
diff options
context:
space:
mode:
authortafaar <[email protected]>2022-11-28 20:03:53 -0800
committertafaar <[email protected]>2022-11-28 20:03:53 -0800
commit8b9e2d64bd0ba670fab56ffefa99a571a2df31a6 (patch)
treec0ae535146111b2ee294c1fc627092e9f5c50c85 /BlankConsoleLab/BlankConsoleLab.cpp
parentfirst commit (diff)
downloadcst116-lab3-hill-8b9e2d64bd0ba670fab56ffefa99a571a2df31a6.tar.xz
cst116-lab3-hill-8b9e2d64bd0ba670fab56ffefa99a571a2df31a6.zip
added functions
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp68
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);
+
+
+
+}
+