-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar.c
177 lines (161 loc) · 4.07 KB
/
car.c
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
#include <stdio.h>
#include "header.h"
/* Outline
all vars
float carRental;
int milesDriven;
float milesReimbers;
float parkingFees;
float taxiFees;
1. amount of car rentals
2. miles driven
3. parking fees
4. taxi fees
*/
/* Car Rental Fees Function */
float carRentalFees()
{
float carRental = 0;
// Car Rental Fees Inputs
printf("Did you rent a car?(y or n): ");
char yesOrNo[6];
scanf("%s", &yesOrNo);
if (yesOrNo[0] == 'y')
{
GET_RENTALCOST:
printf("Enter any car rental fees: $");
scanf("%f", &carRental);
if (carRental <= 0 || carRental > 1000)
{
printf("Error: Please enter a valid amount...");
goto GET_RENTALCOST;
}
}
else
{
carRental = 0;
return carRental;
}
if (carRental <= 0)
{ // error handeling for negatives
printf("Error: Please enter a positive number");
carRental = 0;
}
return carRental;
}
/* Mile Fees Function */
float mileFees()
{
printf("Enter your total miles driven: ");
int milesDriven = 0;
scanf("%d", &milesDriven);
float milesReimbers = 0; // Calculated mile gas costs
// Calculate Mile Fees
if (milesDriven <= 0)
{ // check for 0 or < 0
milesReimbers = 0;
}
else
{ // calculation with miles driven
milesReimbers = (milesDriven * 0.27);
}
return milesReimbers;
}
/* Parking Fees Function */
float calculateParkingFees(int numOfDays)
{
float parkingFees;
int parkingDays;
// Parking Fees Inputs
// Parking Days Scan
GET_PARKING_DAYS:
printf("Enter the number of days you used parking: ");
scanf("%d", &parkingDays);
// Check Parking Days
if (parkingDays > numOfDays || parkingDays < 0)
{
printf("Please enter a correct number of days. You may not exceed %d days.", numOfDays);
parkingDays = 0;
goto GET_PARKING_DAYS;
}
else
{
// Check for 0
if (parkingDays = 0)
{
parkingFees = 0;
}
else
{
// Parking Fees Scan
GET_PARKING:
printf("Enter your total parking fees: $");
scanf("%f", &parkingFees);
// Check Parking Fees
if (parkingFees < 0 || parkingFees > 1000)
{
printf("Error: Enter a valid amount of money...");
parkingFees = 0;
goto GET_PARKING;
}
else
{
// Calculate Parking Fees
parkingFees = parkingFees - (6 * parkingDays);
}
}
}
return parkingFees;
}
// Calculate Taxi Fees
float calculateTaxiFees(int numOfDays)
{
char taxiUse[10];
float taxiFee = 0;
int taxiDays = 0;
// Ask if taxi was used
printf("Did you use a taxi on your trip?(y or n): ");
scanf("%s", &taxiUse[0]);
if (taxiUse[0] == 'y')
{
// Taxi Days Scan
TAXI_FEE_DAYS:
printf("How many days did you use a taxi?: ");
scanf("%d", &taxiDays);
// Check Taxi Days
if (taxiDays > numOfDays || taxiDays < 0)
{
printf("Please enter a correct number of days. You may not exceed %d days.", numOfDays);
taxiDays = 0;
goto TAXI_FEE_DAYS;
}
else
{
// Check for 0
if (taxiDays = 0)
{
taxiFee = 0;
}
else
{
// Taxi Fees Scan
TAXI_FEES:
printf("Enter your total taxi fees: $");
scanf("%f", &taxiFee);
// Check Taxi Fees
if (taxiFee < 0 || taxiFee > 1000)
{
printf("Error: Enter a realistic amount of money...");
taxiFee = 0;
goto TAXI_FEES;
}
else
{
// Calculate Taxi Fees
taxiFee = taxiFee - (10 * taxiDays);
}
}
}
}
return taxiFee;
}