blob: 384e3c4bb2fae07329c3f586522cd5e0f49aa6ad (
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
|
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
/*
* Benjamin Smith
* CST 116
* Lab 3
*/
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int counter = 0;
int pickup[50], dropoff[50], passengers[50];
float distance_trav[50], fare[50], toll[50];
double total_fare[50], cost_per_mile[50];
string filename = "";
void Other_Calculations(double money[], int count_var);
float Fare_Calc(double moneys[]);
int main()
{
ifstream infile;
infile.open("C:\\Users\\cowpi\\source\\repos\\cst116-lab3-Smith-Benjamin\\large.txt");
if (infile.is_open()) {
while (!infile.eof()) {
infile >> pickup[counter] >> dropoff[counter] >> passengers[counter] >> distance_trav[counter] >> fare[counter] >> toll[counter];
counter++;
}
infile.close();
}
else {
cout << "There was an error loading the in file. You may need to reset its address to one on your local device." << endl;
system("pause");
return 0;
}
cout << "Please enter the name of the file you wish to export the results into" << endl << "You must include the \".txt\" at the end of your file name: ";
cin >> filename;
ofstream outfile;
outfile.open(filename);
if (outfile.is_open()) {
for (int counting = 0; counting < counter; counting++) {
total_fare[counting] = fare[counting] + toll[counting];
if (distance_trav[counting] != 0)
cost_per_mile[counting] = fare[counting] / distance_trav[counting];
else
cost_per_mile[counting] = 0;
outfile << total_fare[counting] << " " << cost_per_mile[counting] << endl;
}
cout << "The file was correctly creating and/or written to" << endl;
outfile.close();
}
else {
cout << "There was an error creating or writing to the file" << endl;
system("pause");
return 0;
}
return 0;
}
void Other_Calculations(double money[], int count_var, int counting) {
cout << endl << endl << endl;
cout << "The total number of travellers is: " << count_var << "." << endl;
cout << "The total amount of the fares is: " << Fare_Calc(total_fare, counting) << "." << endl;
cout << "The average cost per person is: " << Fare_Calc(total_fare, counting) / count_var << "." << endl;
}
float Fare_Calc(double moneys[], int counting) {
int sum = 0;
for (int count_variable = 0; count_variable < counting; count_variable++) {
sum += total_fare[count_variable];
}
return sum;
}
|