age calculator... :/

This is a discussion on age calculator... :/ within the C Programming forums, part of the General Programming Boards category; Create a program that asks a user of his date of birth, example DECEMBER 11 1977. The program will then ...

  1. #1
    Registered User mikko93's Avatar
    Join Date
    Sep 2011
    Posts
    4

    Unhappy age calculator... :/

    Create a program that asks a user of his date of birth, example DECEMBER 11 1977.
    The program will then calculate his current age. From the example, if the input is
    DECEMBER 11 1977 then the output is 33 years and 8 months.

    #include<stdio.h> only... ty ^_^

    im just a beginners... help me please

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, Mikko!

    There's more than one way to do this, did your instructor or book, have a preference?

    And please, always use the # icon in the advanced editor window to put your code between code tags - otherwise your code is changed to text format, and becomes difficult to study.

  3. #3
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    One way I know of for doing this requires that you know how many days are in every month (including the system for February). From this, it's possible to get age down to the second, even if referring to the age of the USA (you'll need a 64-bit integer for that one). It's mostly just a loop and multiplying. This is as far as I'll get into the details.
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by mikko93 View Post
    Create a program that asks a user of his date of birth, example DECEMBER 11 1977.
    The program will then calculate his current age. From the example, if the input is
    DECEMBER 11 1977 then the output is 33 years and 8 months.

    #include<stdio.h> only... ty ^_^

    im just a beginners... help me please
    How about I give you some help that will stay with your forever...

    Simply this... As my .sig notes every program no matter how simple or complex follows the same 4 basic steps...

    1) Analyse the problem or requirement until you understand it well enough to solve it.

    2) Spend some time planning your solution, blocking out what your code has to do, try different ways see if you can find an "easy way".

    3) Write your code, working in small steps, doing quick compiles and checks as you go.

    4) Test the code, make sure it's doing what you want/need and fix any problems you find.

    Right now you are at part 1 of this process... so think about the problem...

    What are you being asked to do?

    What do you actually need to calculate?
    Do you need hours, minutes and seconds?
    Do you need to worry about changes of century?
    Do leap years matter?

    Perhaps the second most deflating lesson new programmers learn --right after "'Compiles' does not mean 'Works'"-- is that no programmer no matter how skilled or experienced can ever code the solution to a problem he or she does not understand... Writing code is only a small part of the actual programmer's skillset.

    Hint: Based on your description, you should be able to solve this problem in less than 50 lines of code.
    Last edited by CommonTater; 09-15-2011 at 12:28 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Calculator Help
    By cjwenigma in forum C++ Programming
    Replies: 2
    Last Post: 04-25-2007, 12:35 PM
  2. Calculator
    By maxorator in forum Tech Board
    Replies: 3
    Last Post: 10-14-2005, 02:00 AM
  3. Calculator in C?
    By daveS in forum C Programming
    Replies: 5
    Last Post: 08-04-2003, 11:37 AM
  4. Need help in RPN calculator
    By Lost__Soul in forum C Programming
    Replies: 14
    Last Post: 05-29-2003, 03:01 PM
  5. Calculator
    By TonyP in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 11:14 PM

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