Matlab Program to determine Age of object

bengaltiger14
Messages
135
Reaction score
0

Homework Statement



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.
 
Physics news on Phys.org
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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
7K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
11K
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
7K
Replies
9
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K