summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
blob: 64c6659590f139b8924594894bd85c7f49bcd731 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

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

using std::cout;
using std::cin;
using namespace std;

int PickUp[50];
int DropOff[50];
int Passenger[50];

float Distance[50];
float Fare[50];
float Toll[50];
float CPM[50]; //cost per minute

double TotalCost[50];

int NumberEntries;

int ReadData(ifstream& file)
{
	int f = -1; //f is the number of entries

	while (!file.eof())
	{
		f++;

		file >> PickUp[f] >> DropOff[f] >> Passenger[f] >> Distance[f] >> Fare[f] >> Toll[f];

		TotalCost[f] = Fare[f] + Toll[f];

		if (Distance[f] != 0)
		{
			CPM[f] = Fare[f] / Distance[f];

		}

		else CPM[f] = 0;

	}
	f++;

	return f;

}

void GenerateTotals(int NumberEntries)
{
	int PassengersTotal = 0;
	double TotalPaid = 0;

	for (int i = 0; i <= NumberEntries; i++)
	{
		PassengersTotal += Passenger[i];
		TotalPaid += TotalCost[i];
	}

	cout << "Total passenger count ->> " << PassengersTotal << endl;
	cout << "Total paid ->> " << TotalPaid << endl;
	cout << "The average cost per person is ->> $" << TotalPaid / PassengersTotal << endl;
	cout << "Total trips ->> " << NumberEntries << endl;

}

int main()
{
	ifstream inFile;
	string fileName;

	cout << fixed << setprecision(2);

	while (!inFile.is_open()) {

		cout << "Enter your file name with .txt extension ->>" << endl;
		cin >> fileName;

		inFile.open(fileName);

		if (inFile.is_open()) {
		
			cout << "\nOpened " << fileName << endl;

		}
		else {

			cout << "\nCould not open " << fileName << endl;
		}
		cout << endl;
	}

	int NumberEntries = ReadData(inFile);

	GenerateTotals(NumberEntries);
}