diff options
| author | Birducken <[email protected]> | 2022-11-29 13:39:16 -0800 |
|---|---|---|
| committer | Birducken <[email protected]> | 2022-11-29 13:39:16 -0800 |
| commit | bc6ce66dc7656a2c056e0c6c33bd81bde5cfc585 (patch) | |
| tree | f44457621686c2e322c9d4ddf7d8c47b5fbb3e32 /BlankConsoleLab/cst116-lab3-stark.cpp | |
| parent | Added summary. (diff) | |
| download | archived-cst116-lab3-stark-bc6ce66dc7656a2c056e0c6c33bd81bde5cfc585.tar.xz archived-cst116-lab3-stark-bc6ce66dc7656a2c056e0c6c33bd81bde5cfc585.zip | |
Added comments.
Diffstat (limited to 'BlankConsoleLab/cst116-lab3-stark.cpp')
| -rw-r--r-- | BlankConsoleLab/cst116-lab3-stark.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/BlankConsoleLab/cst116-lab3-stark.cpp b/BlankConsoleLab/cst116-lab3-stark.cpp index e072d68..b4cca4c 100644 --- a/BlankConsoleLab/cst116-lab3-stark.cpp +++ b/BlankConsoleLab/cst116-lab3-stark.cpp @@ -1,3 +1,7 @@ +// Trenton Stark +// CST 116 +// Lab 3 + #include <iostream> #include <fstream> #include <string> @@ -12,7 +16,7 @@ using std::setw; using std::setprecision; using std::fixed; -const int width = 10; +const int width = 10; //Affects all tables void readFile(ifstream& fin, double fares[], int& totalPass); void summary(double fares[], int& totalPass); @@ -20,9 +24,10 @@ void summary(double fares[], int& totalPass); int main() { ifstream fin; string fName; - double fares[50] = { 0 }; + double fares[50] = { 0 }; //Initializes all cells to 0 int totalPass = 0; + //Loops prompt until user enters openable file do { cout << "Input file name: "; cin >> fName; @@ -34,8 +39,8 @@ int main() { 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); - summary(fares, totalPass); + readFile(fin, fares, totalPass); //Inputs data into fares and totalPass while printing out file contents + summary(fares, totalPass); //Uses fares and totalPass to create a summary } void readFile(ifstream& fin, double fares[], int& totalPass) { @@ -43,11 +48,11 @@ void readFile(ifstream& fin, double fares[], int& totalPass) { int pick, drop, pass; double dist, fare, toll, total, cosMi; - cout << fixed << setprecision(2); + cout << fixed << setprecision(2); //Formats the output down to two decimal points while (!(fin.eof())) { fin >> pick >> drop >> pass >> dist >> fare >> toll; total = fare + toll; - if (dist == 0) { + if (dist == 0) { //Checks if there will be a division by zero, if so set cosMi to 0 cosMi = 0; } else { @@ -63,9 +68,9 @@ void readFile(ifstream& fin, double fares[], int& totalPass) { } void summary(double fares[], int& totalPass) { - float totalPaid = 0, average; + float totalPaid = 0, average; //Totals paid must start as zero because each cell is added to the total int i; - for (i = 0; i < 50; i++) { + for (i = 0; i < 50; i++) { //Adds all cells regardless of how many were written because unwritten cells will be 0 totalPaid += fares[i]; } average = totalPaid / totalPass; |