Converting seconds to hours in decimal form?

This is a discussion on Converting seconds to hours in decimal form? within the C Programming forums, part of the General Programming Boards category; I'm trying to convert seconds to hours. I'd like to be able to convert 3600 to read 1.0 and 5400 ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    2

    Converting seconds to hours in decimal form?

    I'm trying to convert seconds to hours. I'd like to be able to convert 3600 to read 1.0 and 5400 (1 and 1/2 hours) to 1.5 and so on..

    If anybody could shed some light on this simple problem I'd greatly appreciate it!

    Thank you.

  2. #2
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    You'll kick yourself when you see this one.

    Code:
    time_val = 5400;
    
    time_dec = time_val / 3600;
    All you have to do is divide by 3600.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2
    Yeah. I guess you were right.

    This i what I did.

    Code:
    #include <stdio.h>
    
    #define SECSPERHOUR     3600
    
    int main(void)
    {
            float secs=7100;
    
            secs = secs / SECSPERHOUR;
    
            printf("Hours: %.02f\n", secs);
    }

  4. #4
    Registered User
    Join Date
    Feb 2006
    Location
    Great India
    Posts
    24
    Hmmmmmmmmm
    Where is the return statement in the code ?

    Don't you think it's not a cool habit of writing code.Just return some integer to main(). Why you have forced main() to stay without food ?


    REAL NAPSTER

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. time converting
    By kumar14878 in forum C Programming
    Replies: 1
    Last Post: 04-29-2005, 01:04 AM
  2. Time between Military Hours
    By StarOrbs in forum C++ Programming
    Replies: 18
    Last Post: 03-01-2005, 05:46 PM
  3. My UserControls dissapear off my form
    By zMan in forum C# Programming
    Replies: 2
    Last Post: 09-15-2004, 08:55 AM
  4. Algo for create hours and minutes with given seconds
    By BianConiglio in forum C Programming
    Replies: 6
    Last Post: 05-30-2004, 06:50 PM
  5. Converting MInutes to Hours and MInutes
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 08-30-2001, 08:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21