-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMy Variable (Travel).cpp
112 lines (81 loc) · 2.71 KB
/
My Variable (Travel).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
// My Variable (Travel).cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void travCost(float &air, float &milesPrice, float &parkingPrice, float &taxiPrice);
int main()
{
float a, b, c, d;
travCost(a, b, c, d);
cout << "Your air miles are: " << fixed << setprecision(2) << a<<endl;
cout << "Your rental miles are: "<< b<<endl;
cout << "Your parking price is: " <<c<<endl;
cout << "Your taxi cost is: "<< d<<endl;
}
//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;
}
}
}