Parking fee

parking fee calculator.
creat a program that will ask the user to input the the time that car enters the parking lot and the time it is about to exit. compute parking fee that the car should pay to the parking clerk. the time is in 24 hours format.

parking fee:
50 php for 3hours
20 php succeeding hours


What is your question?
What is your question?

Maybe "do all the coding for me for free?"

@herbskid, this isn't a homework site, we won't do the work for you.

If you have written code to try to fulfill the assignment objective please post it. If the code doesn't do what you expect say so.

We will help you if you are having problems, but you have to show you'd made an effort on your own.
The question is, "How do I get out of paying my parking fee?"
@zapshe, those are some quite generously low parking fees. Where I live most short term parking lots/garages charge an amount for every 15 minutes, or portion thereof. Drive into the lot, it's a 15 minute charge. No initial bulk rate.

There are a couple of long term rated lots, they are usually a flat fee per day/week/month. They are not set up to handle short term parking.
I live in a "big" city but it's not crowded, so parking is never regulated like this. I've even seen a parking ticket in my life. The downtown area has things like that, but there's usually free parking on a few curbs that'll be free.
"How do I get out of paying my parking fee?"
Put "NULL" as your license plate: https://www.wired.com/story/null-license-plate-landed-one-hacker-ticket-hell/
Too bad the site doesn't allow direct linking of pictures, this one seems appropriate for how the conversation is going:

https://breakbrunch.com/wp-content/uploads/2016/04/kickass-funny-picture-122115-1.jpg
LOL, these are too much xD
Returning to the original question, the program needs to do the following:
- Input the entry and exit time.
- Compute the number of hours that elapsed.
- Compute the parking fee from the number of elapsed hours.
- Print the parking fee.

The trickiest part is computing the elapsed hours. First a question: If someone parks for 2 hours and 12 minutes, does that count as 2 hours or 3? Get clarification from the professor. In most real world parking lots, it counts as 3 hours: the time rounds up.
Entry Exit   Elapsed hours
08:12 08:13  1
08:12 09:09  1
09:09 08:12  24


I suggest you get the number of hours like this:
- Convert hrs and minutes to total elapsed minutes.
- If the elapsed minutes for the exit time is less than that of the entry time, then the car left the day after it arrived. Add 24*60 minutes to the exit time. In this way, both elapsed times reflect the elapsed minutes from the beginning of the day when the car entered.

Subtract exit-entry to get the total elapsed minutes that the car was in the lot.
elapsed hours is elapsed minutes / 60, but there's a catch: that will round down and you need to round up. There's a handy trick to rounding up, just add 59 to the elapsed minutes. So
rounded_up_hours = (elapsed_minutes+59) / 60;

Okay. Here's how you should write the program. There are lots of steps here but most of them are small incremental changes.

1. Write a program that prompts the user for the time in 24 hr format. Question: does that mean 15:30 or 1530? Whatever it is, have the program print out the hours and minutes separately. Note that we'll be removing this printout code eventually, it's just here for debugging.

Assuming 15:30 format:
Input:
08:21
Output:
8 21


2. Modify the program to prompt for and record the entry time and exit time to the lot. Print out the hours and minutes of both. If you've learning about functions, you might find that a function to read hours and minutes is handy. Maybe something like
void getHrsAndMins(int &hours, int &minutes);

3. Write a function that converts hours and minutes to the total elapsed minutes. Convert both entry and exit time to total elapsed minutes and print the result. Verify by hand that you've got the numbers right.

4. Add the code to compute the rounded up hours:
- Add 24*60 minutes to the exit minutes if the exit < entry
- Compute the total elapsed minutes
- Compute the rounded up hours that the car was in the lot.
Print each of these as you go and verify by hand.

5. Compute the parking fee from the rounded up hours. Print it out.

6 Try some test cases. Do at least the three that I included above.

7. Remove all the debugging output so it just prints the total parking fee.

When you get stuck for more than an hour, post your code, along with any error messages if it won't compile, or the exact input and output if it's giving bad results. Ask specific questions.

Topic archived. No new replies allowed.