Thread: A nice, simple question

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    145

    A nice, simple question

    I have been keeping a log file for how many seconds I have been testing out my latest program, using the clock() function. Now, I want to convert this into days, hours, minutes, and seconds. I know modulus division is involved somewhere, but I never did pay attention to that ...
    "Um...well..."
    -Kyoto Oshiro

  2. #2
    My prof. is beautiful!!!!
    Guest

    Here's how

    Code:
    int a = 7;
    int b = 3;
    
    cout << a%b << endl;
    (or)
    printf("%d", a%b);
    OUTPUT:
    1


    "%" is the modulus "/"


    COOL PROGRAMS @ www.akilla.tk

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    145
    Yes...well...
    I know how to do modulus division, it just leaves a remainder, but I was wondering how I convert seconds into various other time increments? Do I first put the seconds into days, then do modulus division by 24 to get hours????????????????????? Kill me now
    "Um...well..."
    -Kyoto Oshiro

  4. #4
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    An hour has 3600 secs so if you divide the number of secs you have with 3600 you'll get the hour

    Code:
    int totsec=36250; //assuming this value
    int hrs,min,rem; //rem=remainder time
    
    hrs=totsec/3600;
    rem=totsec%3600;
    
    min=rem/60;
    rem=rem%60;
    
    cout<<"30,000 seconds = "<<hrs<<" HOURS, "<<min<<" MINUTES and "<<rem<<" SECONDS";
    the ouptut should be : 10 HOURS, 4 MINUTES and 10 SECONDS

    i hope this is what you are asking..
    -

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    145
    Ah, ihsir, thank you for the help, that is exactly what I am asking
    "Um...well..."
    -Kyoto Oshiro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  2. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple Question recv
    By MicroFiend in forum Networking/Device Communication
    Replies: 4
    Last Post: 08-28-2004, 02:28 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM