-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
355 lines (267 loc) · 10.6 KB
/
main.cpp
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
/* *******************************************************************************************************
* This is the main file that will bring all the functions together into a coherent, working program. *
* It will contain all the variables needed to hold the values for the other functions, as well as *
* any other things required for the program's requirements. *
* *
* This file will be edited and maintained solely by Andrew Roderigues. Any other edits will be *
* removed. *
*********************************************************************************************************/
//Define Function Prototypes
float totalCost(float &airfare, float &meals, float &parking, float &hotel, float &vehicle);
double mealCost(int hourLeave, int minLeave, int hourBack, int minBack, int Days);
void travCost(float &air, float &milesPrice, float &parkingPrice, float &taxiPrice);
void totalDays(int &Days);
void tripTimes(int &hourLeave, int &minLeave, int &hourBack, int &minBack);
void hotelCost(int Days, float &Covered, float ¬Covered);
int main()
{
// Define Local Constants
// Define Local Variables
int Days, hourLeave, minBack, minLeave, hourBack;
float airfare, meals, parking, hotel, vehicle, Covered, notCovered;
// Begin Code
totalDays(Days);
tripTimes(hourLeave, minLeave, hourBack, minBack);
hotelCost(Days, Covered, notCovered);
totalCost(airfare, meals, parking, hotel, vehicle);
mealCost(hourLeave, minLeave, hourBack, minBack, Days);
travCost(airfare, meals, parking, vehicle);
return 0;
}
//Robinson Meckes this function determines the round-trip airfair, Rental Car miles price, Parking price, and taxi price.
void travCost(float &air, float &milesPrice, float &parkingPrice, float &taxiPrice) {
string vehicle;
float miles = 0;
float taxi = 0;
float parking = 0;
//determines the Air-Fair
cout << "How much is your round-trip airfare.\n";
cin >> air;
while (air < 0) {
cout << "Your round trip air-fair must be a must be positive.\n";
cout << "How much was your air-fair?\n";
cin >> air;
}
//Deterermines whether the person uses a rented car or taxi as transportation
cout << "Did you rent a car or did you choose taxi as your form of transportation?\n";
cout << "Enter either car or taxi.\n";
cin >> vehicle;
//cout << "Your input is: " << vehicle << endl;
while (vehicle != "car" && vehicle != "Car" && vehicle != "taxi" && vehicle != "Taxi") {
cout << "You can only enter either car or taxi.\n";
cout << "Did you rent a car or did you choose taxi as your form of transportation?\n";
cin >> vehicle;
}
//If "Car" is choosen
if (vehicle == "car" || vehicle == "Car") {
taxiPrice = 0;
cout << "How many miles did you drive?\n";
cin >> miles;
while (miles < 0) {
cout << "The amount of miles you have drivin must be positive.\n";
cout << "How many miles did you drive?\n";
cin >> miles;
}
milesPrice = miles * .58;
cout << "How much was your fee for parking?\n";
cin >> parking;
while (parking < 0) {
cout << "Your parking fee must be a must be positive.\n";
cout << "How much was your parking fee?\n";
cin >> parking;
}
parkingPrice = parking - 12;
if (parkingPrice < 0) {
parkingPrice = 0;
}
}
//If "TAxi" is choosen
if (vehicle == "taxi" || vehicle == "Taxi") {
milesPrice = 0;
parkingPrice = 0;
cout << "How much was your taxi fee?\n";
cin >> taxi;
while (taxi < 0) {
cout << "The price that you have spent on your taxi must be positive.\n";
cout << "How much was your taxi fee?\n";
cin >> taxi;
}
taxiPrice = taxi - 40;
if (taxiPrice < 0) {
taxiPrice = 0;
}
}
}
/*
Made by: Ran Xu
This function use pass by reference to ask the user for the total number of days in the trip
*/
void totalDays(int &Days) {
cout << "Enter the total number of days spent on the trip: ";
cin >> Days;
while ((Days <= 0) || (cin.fail())) {
cin.clear();
//cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Error, negative number or non numeric value or 0 days\nEnter the total number of days spent on the trip: ";
cin >> Days;
}// (totalDays)(while)
}// (totalDays)
#include <string>
/*
Made by: Ran Xu
This function use pass by reference to ask the user for the hour and minute for the first and last day of the trip
with this combine with total number of days we can calculate how many breakfast, lunch, and dinner meals the user will have
*/
void tripTimes(int &hourLeave, int &minLeave, int &hourBack, int &minBack) {
cout << "Enter the hour of departure on the first day of the trip in military time: ";
cin >> hourLeave;
while ((hourLeave > 24)||(hourLeave < 1) || (cin.fail())) {
cin.clear();
// cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Error, hour should be between 1 to 24\nEnter the hour of departure on the first day of the trip in military time: ";
cin >> hourLeave;
}// (tripTimes)(while)
cout << "Enter the minute of departure on the first day of the trip: ";
cin >> minLeave;
while ((minLeave > 59) || (minLeave < 0) || (cin.fail())) {
cin.clear();
// cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Error, minute should be between 0 to 59\nEnter the minute of departure on the first day of the trip: ";
cin >> minLeave;
}// (tripTimes)(while)
cout << "Departure time is " << hourLeave << ":" << minLeave << "\n";
cout << "Enter the hour of arrival back home on the last day of the trip in military time: ";
cin >> hourBack;
while ((hourBack > 24) || (hourBack < 1) || (cin.fail())) {
cin.clear();
// cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Error, hour should be between 1 to 24\nEnter the hour of arrival back home on the last day of the trip in military time: ";
cin >> hourBack;
}// (tripTimes)(while)
cout << "Enter the minute of arrival back home on the last day of the trip: ";
cin >> minBack;
while ((minBack > 59) || (minBack < 0) || (cin.fail())) {
cin.clear();
// cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Error, minute should be between 0 to 59\nEnter the minute of arrival back home on the last day of the trip: ";
cin >> minBack;
}// (tripTimes)(while)
cout << "Return time is " << hourBack << ":" << minBack << "\n";
}// (tripTimes)
/*
Made by: Ran Xu
This function use pass by reference and value to calculate the amount covered and amount pay for hotel expenses
that will add onto the pre existing amount of covered and not covered fees
*/
void hotelCost(int Days, float &Covered, float ¬Covered) {
float Cost, Pay,Free;
cout << "What is the total cost for hotel expenses?: $";
cin >> Cost;
Free = (Days - 1) * 90.0;
Covered = Covered + Free;
Pay = Cost - Free;
notCovered = notCovered + Pay;
cout << "Amount covered for hotel expenses: $" << fixed << setprecision(2) << Free <<
"\nAmount not covered for hotel expenses: $" << Pay;
}// (hotelCost)
//mealCost function written by Andrew Hoyt
double mealCost(int hourLeave, int minLeave, int hourBack, int minBack, int Days)
{
double userTally;
double userTotal = 0;
double outOfPocket = 0;
int count = 0;
// loop to collect all breakfast meal costs
while (count < Days) {
count = count + 1;
cout << "What was the cost of breakfast on day " << count << "?" << endl;
cin >> userTally;
// input validation loop
while (userTally < 0) {
cout << "Please enter a non-negative value for the cost of this meal.";
cin >> userTally;
}
if (userTally < 18.00) {
cout << "The cost for this meal will be covered." << endl;
userTotal = userTotal + userTally;
}
if (userTally > 18.00) {
cout << "Only $18.00 of this meal will be covered, the user will pay the difference." << endl;
outOfPocket = outOfPocket + (userTally - 18.00);
userTotal = userTotal + 18.00;
}
}
count = 0;
// loop to collect all lunch meal costs
while (count < Days) {
count = count + 1;
cout << "What was the cost of lunch on day " << count << "?" << endl;
cin >> userTally;
// input validation loop
while (userTally < 0) {
cout << "Please enter a non-negative value for the cost of this meal.";
cin >> userTally;
}
if (userTally < 12.00) {
cout << "The cost for this meal will be covered." << endl;
userTotal = userTotal + userTally;
}
if (userTally > 12.00) {
cout << "Only $18.00 of this meal will be covered, the user will pay the difference." << endl;
outOfPocket = outOfPocket + (userTally - 12.00);
userTotal = userTotal + 12.00;
}
}
count = 0;
// loop to collect all dinner meal costs
while (count < Days) {
count = count + 1;
cout << "What was the cost of dinner on day " << count << "?" << endl;
cin >> userTally;
// input validation loop
while (userTally < 0) {
cout << "Please enter a non-negative value for the cost of this meal.";
cin >> userTally;
}
if (userTally < 20.00) {
cout << "The cost for this meal will be covered." << endl;
userTotal = userTotal + userTally;
}
if (userTally > 12.00) {
cout << "Only $18.00 of this meal will be covered, the user will pay the difference." << endl;
outOfPocket = outOfPocket + (userTally - 20.00);
userTotal = userTotal + 20.00;
}
}
// accounting for time user left, probably will need revision, i don't think this is right
if (hourLeave < 0700) {
userTotal = userTotal - 18.00;
}
if (hourLeave < 1200) {
userTotal = userTotal - 12.00;
}
if (hourLeave < 1800) {
userTotal = userTotal - 20.00;
}
return 0;
}
// Functions - Travel Expenses.cpp : Defines the entry point for the console application.
//
float totalCost(float &airfare, float &hotel, float &vehicle, float &meals, float &parking)
{
float total;
total= airfare+hotel+vehicle+meals+parking;
cout << "The total cost of your trip was: " << endl;
cout << "\t-------------------------";
cout << "\t\t\t Airfare: $"<< airfare;
cout << "\t\t\t Hotel: $"<< hotel;
cout << "\t\t\t vehicle: $" << vehicle;
cout << "\t\t\t Meals: $" << meals;
cout << "\t\t\t Parking: $" << parking;
cout << "\t-------------------------";
cout << "The cost of your trip was: $" << total << endl;
}