| | |
parking fee
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2005
Posts: 1
Reputation:
Solved Threads: 0
i'm having a trouble getting this right ..
Write a program to calculate parking fee for customers who park their vehicles in a parking lot when the following information is given:
The time the vehicle entered the lot (in 24-hour format, without a colon, such as 1645)
The time the vehicle left the lot, also in 24-hour format without a colon.
To calculate the actual time spent in the parking lot, you may use this algorithm (it's not the only way to do it):
Compare the minute portion of the leaving and entering time. If the first one is smaller than the second,
Add 60 to the minute portion of the leaving time.
Subtract 1 from the hour portion of the leaving time.
Subtract the hour portions.
Subtract the minute portions
was try using the split hour to calculate the hourly and minutes but it didnot come out right ..
<< moderator edit: added [code][/code] tags >>
i'm sort of new to this .. please help me out ..
thank you =)
Write a program to calculate parking fee for customers who park their vehicles in a parking lot when the following information is given:
The time the vehicle entered the lot (in 24-hour format, without a colon, such as 1645)
The time the vehicle left the lot, also in 24-hour format without a colon.
To calculate the actual time spent in the parking lot, you may use this algorithm (it's not the only way to do it):
Compare the minute portion of the leaving and entering time. If the first one is smaller than the second,
Add 60 to the minute portion of the leaving time.
Subtract 1 from the hour portion of the leaving time.
Subtract the hour portions.
Subtract the minute portions
was try using the split hour to calculate the hourly and minutes but it didnot come out right ..
C++ Syntax (Toggle Plain Text)
cout << "Time entered? "; cin >> enter; cout << "Time departed? "; cin >> exit; minutesEnter = enter % 60; hoursEnter = enter / 60; minutesExit = exit + 60; hoursExit = exit - 1; cout << fixed; cout.precision(2); cout << setfill('0'); cout << "Time in: " << hoursEnter << ":" << setw(2) << minutesEnter << endl; cout << "Time out: " << hoursExit << ":" << setw(2) << minutesExit << endl;
i'm sort of new to this .. please help me out ..
thank you =)
•
•
•
•
Originally Posted by dazzer143
Compare the minute portion of the leaving and entering time. If the first one is smaller than the second,
Add 60 to the minute portion of the leaving time.
Subtract 1 from the hour portion of the leaving time.
Subtract the hour portions.
Subtract the minute portions
minutesEnter = enter % 60;
hoursEnter = enter / 60;
minutesExit = exit + 60;
hoursExit = exit - 1;
Bare ONE thing in mind. This is normal MATHEMATICS for the computer and not TIME!
So, what you should do is very simple.
Compare the minutes of both times by using modulus 100.
If exit minute is smaller than entry, add 60 to exit time and minus 100 also to exit time. Then you minus them like a normal math sum.
Else, you just minus them like any other normal math sum.
Take example enter time is 1645 while exit time is 1715.
Why I use modulus is that I only want the minutes and not the hours.
So, when I modulus 1645 with 100 I get 16 extra 45. Right?
And moduls 1715 with 100 I get 17 extra 15. Right?
Then I compare 15 and 45. (obviously 45 is bigger)
So, I add 60 to exit. (1715+60=1775)
Then, minus 100 (as in minus 1 hour) from from exit. (1775-100=1675)
So, now exit holds the value of 1675 while enter is still 1645.
Finally, you minus 1675 and 1615 to get 30!
HOWEVER, since you enter 1645 BUT you want a display 16:45 right?
You'll need to have 2 variables. One to hold the modulus 100 result (which would be the minutesEnter / minutesExit) and another to hold the sum of enter/exit divided by 100 (which would be the hoursEnter / hoursExit).
Hope this helps. Good luck!
Other way is get everything on minutes
SAME apply to live time
than small if statement which check
<< moderator edit: added [code][/code] tags >>
C++ Syntax (Toggle Plain Text)
enterMin=enter%100; //enterMin is int enterHour=enter/100; //enterHour is int enterTime=(eneterHour * 60) + enterMin; //which give you enter time in minutes
SAME apply to live time
than small if statement which check
C++ Syntax (Toggle Plain Text)
if (enterTime < leaveTime) { c=leaveTime - enterTime; //total parking time in minutes b=c/60; //Hours of parking a=c%60; //minutes of parking } else if (enterTime > leaveTime) { d=1440-enterTime; //1440 is 24hour in minutes and you get time till midnight c=d+leaveTime; //total parking time b=c/60; //Hours of parking a=c%60; //minutes of parking } else { SOME MESSAGE SAYING THAT PARKING TIME IS EXACTLY 24HOURS OR NULL }
![]() |
Similar Threads
- parking garage charges (C++)
- I need to write a C++ Code from the following info. HOW DO I... (C++)
- Need help with programming! (C)
- VB project (Visual Basic 4 / 5 / 6)
- Can't see the program execute (C++)
Other Threads in the C++ Forum
- Previous Thread: Controlling Hardware
- Next Thread: What's wrong with string.replace()?
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






