-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prerelease Solution 2020.txt
248 lines (229 loc) · 9.37 KB
/
Prerelease Solution 2020.txt
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
Module Module1
Sub Main()
Dim days() As String = {"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"}
Dim mornmaxhours() As Decimal = {8, 2, 2, 2, 2, 2, 4}
Dim evemaxhours() As Decimal = {8, 8, 8, 8, 8, 8, 8}
Dim mornprices() As Decimal = {2, 10, 10, 10, 10, 10, 3}
Dim eveprices() As Decimal = {2, 2, 2, 2, 2, 2, 2}
Const mornstarthour = 8
Const mornfinishhour = 15
Const evestarthour = 16
Const evefinishhour = 23
Const noparkstarthour = 0
Const noparkfinishhour = 7
Const morndiscount = 0.9
Const evediscount = 0.5
Dim day As String
Dim valid, isfpn, fpncheck, done As Boolean
Dim index, hour_arrival, hours_leave, maxhourspark, n, sum As Decimal
Dim mornhourspark, evehourspark, mornprice, eveprice As Decimal
Dim price, daily_total, amount_paid As Decimal
Dim yesno As Char
Dim input, fpn As String
valid = False
Do
Console.Write("Enter the day: ")
day = LCase(Console.ReadLine())
index = Array.IndexOf(days, day)
If Not index = -1 Then
valid = True
Else
Console.WriteLine("Please enter the correct day.")
End If
Loop Until valid
Console.WriteLine("Thank you.")
valid = False
Do
Console.Write("Any entries Y/N: ")
yesno = LCase(Console.ReadLine())
Select Case yesno
Case "n"
valid = True
done = True
Case "y"
valid = True
done = False
Case Else
Console.WriteLine("Please enter Y or N.")
End Select
Loop Until valid
daily_total = 0
While Not done
valid = False
Do
Console.Write("Enter the hour of arrival: ")
input = Console.ReadLine()
If Not IsNumeric(input) Then
Console.WriteLine("Please enter a number.")
Else
hour_arrival = Val(input)
Select Case hour_arrival
Case noparkstarthour To noparkfinishhour
Console.WriteLine("Cannot park between 0 and 8.")
Case mornstarthour To evefinishhour
valid = True
Case Else
Console.WriteLine("Please enter the correct hour of arrival.")
End Select
End If
Loop Until valid
Console.WriteLine("Thank you.")
index = Array.IndexOf(days, day)
valid = False
Do
Console.Write("Enter how many hours to leave your car: ")
input = Console.ReadLine()
If Not IsNumeric(input) Then
Console.WriteLine("Please enter a number.")
Else
hours_leave = Val(input)
maxhourspark = 24 - hour_arrival
If hour_arrival < evestarthour Then
If maxhourspark > mornmaxhours(index) Then maxhourspark = mornmaxhours(index)
Else
If maxhourspark > evemaxhours(index) Then maxhourspark = evemaxhours(index)
End If
If hours_leave <= maxhourspark And hours_leave > 0 Then
valid = True
Else
Console.WriteLine("Please enter the hours less than or equal to " & maxhourspark & ".")
End If
End If
Loop Until valid
Console.WriteLine("Thank you.")
valid = False
Do
Console.Write("Do you have a frequent parking number Y/N: ")
yesno = LCase(Console.ReadLine())
Select Case yesno
Case "y"
valid = True
isfpn = True
Case "n"
valid = True
isfpn = False
Case Else
Console.WriteLine("Please enter Y or N.")
End Select
Loop Until valid
Console.WriteLine("Thank you.")
If isfpn Then
valid = False
Do
Console.Write("Enter your frequent parking number: ")
fpn = UCase(Console.ReadLine())
If Not Len(fpn) = 5 Then
Console.WriteLine("The FPN should be 5 digits.")
Else
valid = True
If Not IsNumeric(fpn.Chars(0)) Then
valid = False
ElseIf Not IsNumeric(fpn.Chars(1)) Then
valid = False
ElseIf Not IsNumeric(fpn.Chars(2)) Then
valid = False
ElseIf Not IsNumeric(fpn.Chars(3)) Then
valid = False
ElseIf Not IsNumeric(fpn.Chars(4)) And Not fpn.Chars(4) = "X" Then
valid = False
End If
If Not valid Then
Console.WriteLine("The FPN must be numeric Modulo 11 format.")
End If
End If
Loop Until valid
Console.WriteLine("Thank you.")
End If
If isfpn Then
sum = 0
n = Val(fpn.Chars(0))
n = n * 5
sum = sum + n
n = Val(fpn.Chars(1))
n = n * 4
sum = sum + n
n = Val(fpn.Chars(2))
n = n * 3
sum = sum + n
n = Val(fpn.Chars(3))
n = n * 2
sum = sum + n
If fpn.Chars(4) = "X" Then
n = 10
Else
n = Val(fpn.Chars(4))
End If
n = n * 1
sum = sum + n
If (sum Mod 11) = 0 Then
fpncheck = True
Else
fpncheck = False
End If
End If
REM If hour_arrival < evestarthour Then
REM price = hours_leave * mornprice(index)
REM If fpncheck Then price = price * morndiscount
REM Else
REM price = hours_leave * eveprice(index)
REM If fpncheck Then price = price * evediscount
REM End If
mornhourspark = evestarthour - hour_arrival
evehourspark = hours_leave - mornhourspark
If evehourspark < 0 Then
mornhourspark = mornhourspark + evehourspark
evehourspark = 0
End If
mornprice = mornhourspark * mornprices(index)
eveprice = evehourspark * eveprices(index)
If isfpn And fpncheck Then
mornprice = mornprice * morndiscount
eveprice = eveprice * evediscount
End If
price = mornprice + eveprice
If isfpn Then
If fpncheck Then
Console.WriteLine("Your FPN was accepted and discounted price is " & price & ".")
Else
Console.WriteLine("Your FPN was rejected and undiscounted price is " & price & ".")
End If
Else
Console.WriteLine("Your undiscounted price without FPN is " & price & ".")
End If
valid = False
Do
Console.Write("Enter the amount paid: ")
input = Console.ReadLine()
If Not IsNumeric(input) Then
Console.WriteLine("Please enter a number.")
Else
amount_paid = val(input)
If amount_paid >= price Then
valid = True
daily_total = daily_total + amount_paid
Else
Console.WriteLine("Please enter an amount greater or equal to " & price & ".")
End If
End If
Loop Until valid
Console.WriteLine("Thank you.")
valid = False
Do
Console.Write("Any further entries Y/N: ")
yesno = LCase(Console.ReadLine())
Select Case yesno
Case "n"
valid = True
done = True
Case "y"
valid = True
done = False
Case Else
Console.WriteLine("Please enter Y or N.")
End Select
Loop Until valid
End While
Console.WriteLine("Daily total for " & day & " is " & daily_total & ".")
Console.ReadLine()
End Sub
End Module