Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 8th, 2006, 7:18 AM   #1
oslan
Newbie
 
Join Date: Feb 2006
Posts: 6
Rep Power: 0 oslan is on a distinguished road
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
oslan is offline   Reply With Quote
Old Feb 8th, 2006, 7:50 AM   #2
java_roshan
Professional Programmer
 
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 5 java_roshan is on a distinguished road
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
java_roshan is offline   Reply With Quote
Old Feb 8th, 2006, 8:02 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 7,025
Rep Power: 12 DaWei will become famous soon enough
Quote:
user_input_start_time = 10.25 /* means 10.25 AM */
When converting your numbers, as mentioned by roshan, you don't want 10.25 to mean 10:25, as it means 10:15. I'm not saying that's what you're doing, just a tip.
__________________
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
DaWei is offline   Reply With Quote
Old Feb 8th, 2006, 8:12 AM   #4
java_roshan
Professional Programmer
 
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 5 java_roshan is on a distinguished road
Quote:
Originally Posted by DaWei
When converting your numbers, as mentioned by roshan, you don't want 10.25 to mean 10:25, as it means 10:15. I'm not saying that's what you're doing, just a tip.
oslan...this would make your programming a bit simpler...I suppose!
__________________
Visit: http://www.somaiya.edu
java_roshan is offline   Reply With Quote
Old Feb 8th, 2006, 5:07 PM   #5
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 5 jim mcnamara is on a distinguished road
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.
jim mcnamara is offline   Reply With Quote
Old Feb 8th, 2006, 9:07 PM   #6
oslan
Newbie
 
Join Date: Feb 2006
Posts: 6
Rep Power: 0 oslan is on a distinguished road
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
oslan is offline   Reply With Quote
Old Feb 9th, 2006, 6:06 AM   #7
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 6 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old Feb 10th, 2006, 3:04 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 7,025
Rep Power: 12 DaWei will become famous soon enough
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)
You are begging for runtime crashes and he is not. I leave it as an exercise for you to refer to the documentation and determine why. Meanwhile, please do not program any equipment on which people's lives depend.
__________________
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
DaWei is offline   Reply With Quote
Old Feb 10th, 2006, 4:07 PM   #9
spydoor
Programmer
 
Join Date: Feb 2005
Posts: 64
Rep Power: 6 spydoor is on a distinguished road
Just don't pay attention to my math
Those 24s should be 60s to get seconds

Time limit on edits?
spydoor is offline   Reply With Quote
Old Feb 10th, 2006, 5:00 PM   #10
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 6 nnxion is on a distinguished road
Quote:
Originally Posted by spydoor
Just don't pay attention to my math
Those 24s should be 60s to get seconds

Time limit on edits?
Yes time limits are there so people don't remove their content.
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
nnxion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:53 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC