1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Program to determine Age of object

  1. Oct 21, 2008 #1
    1. The problem statement, all variables and given/known data

    Write a program to determine the age of an object given the creation date and todays date. The program must contain 6 user input statements (asking for year, month and date of creation, and year,month, todays date) and display the age of the object in days.

    I have already written functions to determine how many days are in a month and to determine if a year is a leapyear. The days in month function has the leap year function inside of it in cases of february

    I have the 6 input statement written and I am now stuggling with the code.

    I have this after the input statements:

    if month1 > month2 || ((month1==month2) && (date1>date2))
    years = (year2 - year1) - 1

    Where do I go from here and am I even doing this correctly?

    Month 1 is the creation month, month 2 is todays month, date 1 is creation date and date2 is todays date.
  2. jcsd
  3. Oct 22, 2008 #2
    You know how many days are in a particular year, so all you have left is to calculate the number of days in the fraction of a year you have left. Just iterate through the months and add the days, keeping track of which year february is in if you happen to pass over a february in this fractional year. That's the trickiest part easily.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Matlab Program to determine Age of object
  1. Matlab Programming (Replies: 5)