Thread: Time between Military Hours

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    59

    Time between Military Hours

    I've been writing a program that calculates the hours and minutes between 2 military times.

    For example the hours and minutes between 0900 and 1730; 1730 and 0900 the next day. Now I just converted all the times to seconds because I find that to be easier.

    this is what I do..

    hours for time 1 = time1 / 100
    minutes for time 1 = time1 % 100
    calculate total no of seconds = (hours * 3600) + (minutes * 60)

    hours for time 2 = time2 / 100
    minutes for time 2 = time2 % 100
    calculate total no of seconds = (hours * 3600) + (minutes * 60)

    Now this is where I have trouble.. I know I can do it with an if statement but we aren't allowed to use that yet...

    remaining total seconds = seconds in 24 hours - abs((total num of secs for time 1 - total num of secs for time 2)

    number of minutes = remaing total seconds / 60
    number of hours = num of minutes / 60

    minutes left over = number of minutes % 60

    Then I output hours and minutes like 8 hours and 30 minutes

    So if I take away the number of seconds in a day in this: remaining total seconds = seconds in 24 hours - abs((total num of secs for time 1 - total num of secs for time 2)

    Then when I want to find the number of hours and minutes between 0900 -> 1730 I get 8 hours and 30 minutes which is correct.

    But if I do 1730 -> 0900 the next morning I still get 8 hours 30 minutes.

    And if I leaving the number of seconds in a day in I get the correct answer for 1730 -> 0900 but not for 0900 -> 1730.

    I would appreciate any help you can give me this is a puzzle for me..
    Last edited by StarOrbs; 02-26-2005 at 08:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Time to seconds program
    By Sure in forum C Programming
    Replies: 1
    Last Post: 06-13-2005, 08:08 PM
  2. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 07:56 AM
  3. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM