![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Feb 2006
Posts: 6
Rep Power: 0
![]() |
need help on how to calculate between 2 input times.
Dear friends,
I would like to get help from you guys on how to calculate the different between 2 input times (in minutes). for example : user_input_start_time = 10.25 /* means 10.25 AM */ user_input_end_time = 11.05 /* means 11.05 AM */ total_diff_time = user_input_end_time - user_input_start_time from the above example , if use calculator, the answer is 0.80, but the actual total_diff_time is only 0.40 (means 40 minutes). How to calculate the above case in C programming. Pls. help me. Kind regards Oslan Last edited by oslan; Feb 8th, 2006 at 7:19 AM. Reason: speeling error |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 5
![]() |
Convert each time entity entered into a single unit of either seconds or minutes and display the answer in minutes/seconds....
i.e. for example if its 1:00 AM (say February 09th 2006) then, you have crossed 3600 seconds on that day... if this is the first login .... if it is 1:36 then it will be 3600 + 36 x 60 = 3600 + 2160 = 5760 seconds for the day .. if this is the second login... The difference in time.... 5760 - 3600 = 2160 seconds Divide by 60 will give u the minutes 2160 / 60 = 36 minutes There might be certain functions in Borland C compiler to directly convert into a single unit for calcuation! Hope you have understood...and this helps u out!
__________________
Visit: http://www.somaiya.edu |
|
|
|
|
|
#3 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 7,025
Rep Power: 12
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers Politically Incorrect |
|
|
|
|
|
|
#4 | |
|
Professional Programmer
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 5
![]() |
Quote:
__________________
Visit: http://www.somaiya.edu |
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 5
![]() |
FWIW- you seem to assume the two times are from today, not 11:30pm and 1:27am tomorrow. You might want to check for that.
Otherwise, you'll have to use standard date routines - difftime, mktime, localtime. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Feb 2006
Posts: 6
Rep Power: 0
![]() |
Dear friends,
Perhaps my earlier explaination was not so clear.. Let me explain again...... Example; I want to calculate the Car Packing fee for certain period of time. For this case, I need to key-in / input the following information; 1. Start_time (the time that the car owner park his/her car) 2. End_time (the time that the car owner leave the parking) So, Duration_car_used_the_parking = End_time - Start_time; once, I've the above duration then I can calculate the parking fee.... In my earlier message, I need help to show me on how to write the above calculation in C programming. I've tried to used difftime function but it doesn't work with the above manual input time. FYI, I'm just start learning C programming and now I'm 'stuck' with my 1st. exercise. Thanking you in advance for your kind help & advice. Regards oslan |
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 6
![]() |
Have a look at time.h.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 7,025
Rep Power: 12
![]() |
Notice the difference between your use of "scanf" and spydoor's:
You:
scanf ("%d",&out_time);
He:
if(sscanf(out_time, "%d:%d", &out_time_hr, &out_time_min) != 2)
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers Politically Incorrect |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Feb 2005
Posts: 64
Rep Power: 6
![]() |
Just don't pay attention to my math
![]() Those 24s should be 60s to get seconds Time limit on edits? |
|
|
|
|
|
#10 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 6
![]() |
Quote:
If you think it should change, say something about it here.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|