diff options
| author | Joe Traver <[email protected]> | 2022-11-28 13:39:02 -0800 |
|---|---|---|
| committer | Joe Traver <[email protected]> | 2022-11-28 13:39:02 -0800 |
| commit | 8160a71372e65e95e2993089975be7d3347ba145 (patch) | |
| tree | 5c74e2c616c5239628438b23ae1ea095b0517199 /BlankConsoleLab | |
| parent | Added functions for final statistics and need tutor help to tweak the remaind... (diff) | |
| download | cst116-lab3-joetraver30-8160a71372e65e95e2993089975be7d3347ba145.tar.xz cst116-lab3-joetraver30-8160a71372e65e95e2993089975be7d3347ba145.zip | |
Fixed issues with code
Diffstat (limited to 'BlankConsoleLab')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index 7292a4c..2adcb04 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -23,9 +23,9 @@ int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], int counter); void PrintTotalsAndSummary(ofstream& outFile, int totalRecords); -void PassengerCount(int psgr[], int counter, int pplt); -void TotalPaid(int tfare[], int counter, int paid); -void AverageCostPerPerson(int paid, int pplt, int ACM); +void PassengerCount(int psgr[], int counter, int &pplt); +void TotalPaid(float tfare[], int counter, float &paid); +void AverageCostPerPerson(float paid, int pplt, float ACM); int main() { @@ -58,9 +58,9 @@ int main() if (outFile.is_open()) { WriteOutputFile(outFile, pick, drop, psgr, dist, fare, toll, record_counter); - PassengerCount(psgr, counter, pplt); - TotalPaid(tfare, counter, paid); //dont know exactly whats happening here - AverageCostPerPerson(paid, pplt, paid); + PassengerCount(psgr, record_counter, pplt); + TotalPaid(tfare, record_counter, paid); + AverageCostPerPerson(paid, pplt, ACM); PrintTotalsAndSummary(outFile, record_counter); outFile.close(); } @@ -100,9 +100,12 @@ int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], { tfare[counter] = fare[counter] + toll[counter]; - CPM[counter] = fare[counter] / dist[counter]; //can't get the check to work - //if (dist[counter] = 0) - //CPM[counter] = 0; + if (dist[counter] == 0) + CPM[counter] = 0; + + else + CPM[counter] = fare[counter] / dist[counter]; + cout << fixed << setprecision(2) << setiosflags(ios::left) << setw(10) << pick[counter] << resetiosflags(ios::left) @@ -125,7 +128,7 @@ void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], floa int counter) { outFile << " Here is the Output File" << endl; - for (int i = 0; i <= counter - 1; i++) + for (int i = 0; i < counter; i++) { outFile << setiosflags(ios::left) << setw(5) << pick[i] << resetiosflags(ios::left) @@ -137,39 +140,39 @@ void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], floa << endl; } } -void PassengerCount(int psgr[], int counter, int pplt) // counter isnt being brought in +void PassengerCount(int psgr[], int counter, int &pplt) { - for (int i = 0; i <= counter; i++) + for (int i = 0; i < counter; i++) { pplt = pplt + psgr[i]; - i++; + } cout << endl << "Total number of passengers transported: " << pplt << endl; } -void TotalPaid(int tfare[], int counter, int paid) // counter isnt being brought in +void TotalPaid(float tfare[], int counter, float &paid) { - for (int i = 0; i <= counter; i++) + for (int i = 0; i < counter; i++) { paid = paid + tfare[i]; - i++; + } - cout << "Total fairs paid: " << paid << endl; + cout << "Total fairs paid: $" << paid << endl; } -void AverageCostPerPerson(int paid, int pplt, int ACM) +void AverageCostPerPerson(float paid, int pplt, float ACM) { ACM = paid / pplt; - cout << "Average cost per person: " << ACM << endl; + cout << "Average cost per person: $" << ACM << endl; } |