summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
blob: 28f2ddca4d5f2c929fcf857cb29eaad016c75941 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

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()
{

    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;

}