Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Pascal-urgent Help!!!

Reply  
Thread Tools
Hillian's Avatar
Member with 395 posts.
 
Join Date: Apr 2004
Location: Illinois
Experience: Intermediate
30-Sep-2006, 01:05 AM #1
Pascal-urgent Help!!!
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.
Attached Files
File Type: zip Pentagon.zip (7.6 KB, 7 views)
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
30-Sep-2006, 02:03 AM #2
Wow, they still teach Pascal. I thought that was dead and buried at least 5 years ago. Last time I even touched it was in 1996. I guess it is good for teaching the basics. I see they haven't gotten into Input Error Checking yet or Procedures and functions. How I loved using Case statements in Pascal.

I will take a look at this weekend if I have time. Like I said. I haven't touched it in 10 years but I still have all my notes and books from those classes. Will have to bring back some brain cells from the dead.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:51 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.