my assignment is:
The sign on the attendant’s booth at the Pentagon parking lot is
PENTAGON VISITOR PARKING
Cars:
First 2 hours free
Next 3 hours 0.50 / hour
Next 10 hours 0.25 / hour
Trucks:
First 1 hour free
Next 2 hours 1.00 / hour
Next 12 hours 0.75 / hour
Senior Citizens: no charge
Write a program that will accept as input a one-character designator (C, T, or S) followed by the number of minutes a vehicle has been in the lot. The program should then compute the appropriate charge and print a ticket for the customer. Any part of an hour is to be counted as a full hour. A loop should be incorporated to allow the user to continue with the program.
my code so far is:
Const
skip = ' ';
Var
vehicle : char; {Type of vehicle}
time : integer; {Amount of time parked hours 2-5}
hrs : integer; {Amount of time parked after 5 hours}
leftover : integer; {leftover minutes of an hour}
cost : real; {Total parking cost for 0-5 hours}
cost2 : real; {Total parking cost for more then 5 hours}
final : real; {Final cost of parking car}
rate : real; {Parking rate per hour under 5}
rate2 : real; {Parking rate over 5 hours}
begin
// Heading
writeln(skip:22,'***********************************');
writeln(skip:22,'* Pentagon Visitor Parking *');
writeln(skip:22,'***********************************');
writeln;
writeln;
// Input
writeln(Skip:20,'*--------------------------------------*');
writeln(skip:20,'| Car = C Truck = T Senior = S |');
writeln(skip:20,'*--------------------------------------*');
writeln;
writeln;
write('Please input type of vehicle: ');
readln(vehicle);
//IF statement for senior citizen
If (vehicle = 's') or (vehicle = 'S') Then
Begin
writeln;
writeln;
writeln('The cost is FREE for senior citizens!');
writeln;
writeln;
writeln;
writeln;
writeln('Thank you for using the Pentagon Visitor Parking Calculator!');
readln
End;
//Read time in if not senior citizen
write('Please input number of minutes vehicle was parked: ');
readln(time);
//Minutes to hours
hrs := time Div 60;
leftover := time Mod 60;
If leftover > 0 Then
hrs := hrs + 1;
//IF statement for car
If (vehicle = 'c') or (vehicle = 'C') Then
If hrs < 2 then
Begin
rate := 0.00;
writeln;
writeln;
writeln('The cost is FREE!');
writeln;
writeln;
writeln;
writeln;
writeln('Thank you for using the Pentagon Visitor Parking Calculator!');
readln
End
Else if (hrs - 2) <= 5 then
Begin
rate := 0.50;
cost := (hrs - 2) * rate;
writeln;
writeln;
writeln('The cost to park your car is: $',cost:2:2);
writeln;
writeln;
writeln;
writeln;
writeln('Thank you for using the Pentagon Visitor Parking Calculator!');
readln
End
Else If (hrs > 5) and (hrs <= 15) Then
Begin
rate2 := 0.25;
cost2 := (hrs - 5) * rate2;
final := (cost + cost2);
writeln;
writeln;
writeln('The cost to park your car is: $',final:2:2);
writeln;
writeln;
writeln;
writeln;
writeln('Thank you for using the Pentagon Visitor Parking Calculator!');
readln
End;
//IF statement for Truck
If (vehicle = 't') or (vehicle = 'T') Then
If hrs < 1 then
Begin
rate := 0.00;
writeln;
writeln;
writeln('The cost is FREE!');
writeln;
writeln;
writeln;
writeln;
writeln('Thank you for using the Pentagon Visitor Parking Calculator!');
End
Else if (hrs - 2) <= 3 then
Begin
rate := 1.00;
cost := (hrs - 2) * rate;
writeln('The cost to park your truck is: $',cost:2:2);
End
Else If (hrs > 3) and (hrs <= 15) Then
Begin
rate2 := 0.75;
cost2 := (hrs - 5) * rate2;
final := (cost + cost2);
writeln;
writeln;
writeln('The cost to park your truck is: $',final:2:2);
writeln;
writeln;
writeln;
writeln;
writeln('Thank you for using the Pentagon Visitor Parking Calculator!');
readln
End
end.
I run into problems when lets say a car is entered and the hours is in between 2-5, it needs to multiply the rate($0.50 times the number of hours between 2-5). For instance if i use 432 as my minutes(time variable) for a car, the code read in the minutes...changes it to hours and if theres 1-59 minutes left over, it rounds the hour up. so in this case it gives you 7 hours,12 minutes which rounds up to 8 hours. the first two hours are free. this leaves six hours now. since 3 of the 6 hours falls in between the 2-5 hour frame, you are charged 1.50 per hour for them three hours. so now were up to $1.50 and have 3 hours left over. these last 3 hours goes into the next category of 6-15 hours at $0.25 per hour.
so this makes the last 3 hours $0.25 each or a total of $0.75. so now you have FREE+$1.50+$0.75= $2.25 as a total to park there in a car for 8 hours.Ive attached the executable of the program for those of you wanting to see it directly. this is coded in Borland Delphi 6.