Thread: calculation birth date as floating number

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    95

    calculation birth date as floating number

    Hi, i want to calculate age of a person so then i try to make an algorithm which is used in a function like (i know to use math.h for abs())
    double age_calculator( int year, int month, int day);
    Code:
        double age_calculator( int year, int month, int day);
        // p means present(current)    
        int pyear=(2014-year)*365;
        int pmonth=(abs(9-month))*30;
        int pday=abs(25-day);
        return (pyear+pmonth+pday)/365.0;
    So, my questions are first how can i use current date, i mean i want to use date of present day instead of 2014,25 and 9. I don't know how i can use date of every day.
    For instance my function returns 14.74 for the parameters; 2000, 01, 01 (for the current day 25/09/2014)
    Thank you for all appreciated answers

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Mar 2014
    Posts
    95
    Quote Originally Posted by stahta01 View Post
    so what ?

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by Ph0x View Post
    so what ?
    So that is a starting point for how you can work with dates/times in a C program.

  5. #5
    Registered User
    Join Date
    Sep 2014
    Location
    SE Washington State
    Posts
    65
    You might remember that there are 365.25 days in a year, take the current date and calculate how many days are left in the year to or from the bithday you are using to get the extra or missing days.
    I think you will have to build variables representing the number of days in each month with February having 28.25 or add in leap years to the variables.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Ph0x View Post
    so what ?
    I was thinking since you posted on the Internet that you knew about hyperlinks; but, it appears to not be true.

    I have added you to my ignore list; this prevents both your time and my time from being wasted.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    What stahta01 was suggesting is that you have a look at the <time.h> header.

    You will save a lot of time in development and learn about a great resource to use in future programs.
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with large number factorial calculation
    By afr_c2011 in forum C++ Programming
    Replies: 2
    Last Post: 01-29-2011, 10:49 AM
  2. Big Floating Number, 100! Not right.
    By KAUFMANN in forum C Programming
    Replies: 7
    Last Post: 01-19-2011, 07:48 PM
  3. Date calculation program
    By putty88 in forum C Programming
    Replies: 5
    Last Post: 04-17-2009, 07:24 AM
  4. floating and double number
    By kashifk in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2003, 09:52 PM
  5. date calculation
    By tuti in forum C Programming
    Replies: 0
    Last Post: 09-02-2002, 04:50 AM