Thread: numbers

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    29

    numbers

    hi!

    I have used gettimeofday() to calculate the difference between a random character that appears in the screen, and a character pressed by a user.
    And i retrieve it in seconds.

    I want to retrieve in centesimals.

    This is not c programming:
    For example: 1,24 seconds
    Centesimals = 4?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    The same timeofday() which returns this?
    Code:
           struct timeval {
                   long tv_sec;        /* seconds */
                   long tv_usec;  /* microseconds */
           };
    Well the answer you seek is stored in the microseconds field

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    29
    yes, that's what i used.
    But how can i get the centesimals only with the microseconds?
    I think that a second haves 1000000 microseconds?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    How about converting one type to the other? Surely you know how to find a specific decimal place or do basic division and / or multiplication?

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    29
    This function is retrieving in seconds:

    Code:
    int time(void) {
      
    int InicialTime, FinalTime, TotalTime;
    struct timeval inicio, fim;
    
      TempoInicio = (inicio.tv_sec + inicio.tv_usec*1.e-6);
      TempoFim = (fim.tv_sec + fim.tv_usec*1.e-6);
      
      TotalTime = FinalTime - InicialTime;
      return TotalTime;
    }
    I want centesimals

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > I think that a second haves 1000000 microseconds?
    Good, so how many microseconds does a centisecond have then?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about random numbers
    By Kempelen in forum C Programming
    Replies: 2
    Last Post: 07-02-2008, 06:28 AM
  2. Help with Rational Numbers (C++)
    By cloudjc in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2008, 04:03 PM
  3. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM