summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirducken <[email protected]>2022-11-29 13:06:46 -0800
committerBirducken <[email protected]>2022-11-29 13:06:46 -0800
commitadb04b264dd1d223c9588bbd132a9d8de3a8519e (patch)
tree930debe724bc46df143e74fb23d8aa1ae1c75dbd
parentAdded file reading system. (diff)
downloadcst116-lab3-stark-adb04b264dd1d223c9588bbd132a9d8de3a8519e.tar.xz
cst116-lab3-stark-adb04b264dd1d223c9588bbd132a9d8de3a8519e.zip
Finished calculations.
-rw-r--r--BlankConsoleLab/cst116-lab3-stark.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/BlankConsoleLab/cst116-lab3-stark.cpp b/BlankConsoleLab/cst116-lab3-stark.cpp
index 0271537..bb8b50b 100644
--- a/BlankConsoleLab/cst116-lab3-stark.cpp
+++ b/BlankConsoleLab/cst116-lab3-stark.cpp
@@ -14,7 +14,7 @@ using std::fixed;
const int width = 10;
-void readFile(ifstream& fin, double fares[], int totalPass);
+void readFile(ifstream& fin, double fares[], int& totalPass);
int main() {
ifstream fin;
@@ -30,11 +30,14 @@ int main() {
cout << "File couldn't be opened. Try again." << endl;
}
} while (!(fin.is_open()));
+ cout << endl;
cout << setw(width) << "Pick:" << setw(width) << "Drop:" << setw(width) << "Pass #:" << setw(width) << "Dist:" << setw(width) << "Fare:" << setw(width) << "Toll:" << setw(width) << "Total:" << setw(width) << "Cost/Mi:" << endl;
readFile(fin, fares, totalPass);
+
}
-void readFile(ifstream& fin, double fares[], int totalPass) {
+void readFile(ifstream& fin, double fares[], int& totalPass) {
+ int i = 0;
int pick, drop, pass;
double dist, fare, toll, total, cosMi;
@@ -48,6 +51,9 @@ void readFile(ifstream& fin, double fares[], int totalPass) {
else {
cosMi = fare / dist;
}
- cout << setw(width) << pick << setw(width) << drop << setw(width) << pass << setw(width) << dist << setw(width) << fare << setw(width) << toll << setw(width) << total << setw(width) << cosMi << endl;;
+ cout << setw(width) << pick << setw(width) << drop << setw(width) << pass << setw(width) << dist << setw(width) << fare << setw(width) << toll << setw(width) << total << setw(width) << cosMi << endl;
+
+ totalPass += pass;
+ fares[i] = total;
}
}