Thread: Time Calculation

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1

    Time Calculation

    im sorry to ask this im sure its a very simple calculation but its really frustrating me

    if i take 2 int variables the 1st is a time such as 1345 (1:45pm)
    the 2nd a duration of time such as 530 (5hours 30min)
    how do i add them together and get the correct time of 1915 (6:15pm)?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > if i take 2 int variables the 1st is a time such as 1345 (1:45pm)
    Convert to minutes - as 13*60+45

    Then do the reverse to recover hours and minutes when you're done.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Representing floats with color?
    By DrSnuggles in forum C++ Programming
    Replies: 113
    Last Post: 12-30-2008, 09:11 AM
  3. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM