Thread: Help with program (integer to seconds)

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    9

    Help with program (integer to seconds)

    Hello,
    I have a small problem w/ this program:
    Program a function seconds_from_int, that given a non-negativeinteger representing an amount of time such that the two last digits represent a number of seconds, the third and fourth digits (from the right) represent a number of minutes, and the remaining leading digitsrepresent a number of hours, computes the corresponding number of seconds. For example, seconds_from_int (210) returns 130; seconds_from_int (11929) returns 4769. If

    the number is small and the digits for the hour, for the minutes or for the tens of seconds
    are missing, they take the value z
    ero, by convention.
    Already coded:
    Code:
    #include <stdio.h>
    #include <math.h>
    
    /int seconds_from_int(int )
    {
        return 
    }
    
    void exercise_1_2 (void)
    {
      int t;
      while (scanf ("%d", &t) != EOF)
      {
        int z = seconds_from_int (t);
        printf ("%d\n", z);
      }
    }
    
    int main(void)
    {
        exercise_1_2();
        return 0;
    }
    
    */
    1 min = 60
    1 hour = 3600
    
    int seconds_from_time(int hr, int mn, int sec)
    {
        return hr * 3600 + mn * 60 + sec;
    }
    
    /*
    Last edited by Grilofuzeta; 10-09-2013 at 03:57 AM.

  2. #2
    11DE784A SirPrattlepod's Avatar
    Join Date
    Aug 2013
    Posts
    485
    seconds_from_int (11929) returns 4769



    What a completely ridiculous thing to do. For the record

    1 * 3600 + 19 * 60 + 29 = 4769

  3. #3
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    use curly brackets for operator aritmatic,
    and returning variable please not a value.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How To Stop A Program After 10 Seconds?
    By envec83 in forum C Programming
    Replies: 6
    Last Post: 11-13-2011, 04:31 AM
  2. Convert seconds to hours, minutes and seconds
    By kkk in forum C Programming
    Replies: 2
    Last Post: 07-26-2011, 10:47 AM
  3. Timing C program always returns 0 seconds.
    By hamsteroid in forum C Programming
    Replies: 6
    Last Post: 03-24-2007, 10:02 AM
  4. Time to seconds program
    By Sure in forum C Programming
    Replies: 1
    Last Post: 06-13-2005, 08:08 PM
  5. Pauseing a program for 3 seconds
    By Queatrix in forum C++ Programming
    Replies: 17
    Last Post: 04-09-2005, 07:35 PM