- #1

- 6

- 0

they have been alive. You can ignore leap years.

## The Attempt at a Solution

I have little experience in MATLAB or programming in general, but a little help to get me started would be appreciated. Thanks

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

In summary: The reason I suggested MM/DD/YYYY format is because it is easier for the user to input the full year (YYYY) rather than just the last two digits (YY). This way, there is no ambiguity in the year and the program can easily calculate the number of days between the two dates.

- #1

- 6

- 0

they have been alive. You can ignore leap years.

I have little experience in MATLAB or programming in general, but a little help to get me started would be appreciated. Thanks

Physics news on Phys.org

- #2

Mentor

- 66,698

- 19,272

bbarke00 said:

they have been alive. You can ignore leap years.

## The Attempt at a Solution

I have little experience in MATLAB or programming in general, but a little help to get me started would be appreciated. Thanks

Welcome to the PF.

How many days are there in each month? (Hint -- you will need to list each month)

How many days are there in each (non-leap) year?

What can you do with those sets of numbers, given their birthdate and current date, to find out how many days they've been alive.

Show us some initial work (can just be pseudo-code for now)...

- #3

- 6

- 0

- #4

Mentor

- 37,492

- 9,745

- #5

Mentor

- 66,698

- 19,272

bbarke00 said:

In addition to the MATLAB resources that Mark44 pointed you to, often in programming, we do a first pass in "pseudocode" or just plain words to map out what we want the program to do. You don't need to dive straight into coding in C or Java or MATLAB or whatever. It helps you to stand back and see what the overall flow of the program should be.

So can you take a cut at what the program should do overall?

Like,

** Prompt & User inputs today's date in MM/DD/YYYY (or whatever) format

** Prompt & User inputs a birthdate in MM/DD/YYYY (or whatever) format

** Count up the number of days between the two dates

** Output the answer

Now, can you think of some ways to help you count up the number of days between the two dates? There are several ways you could do it, and some of them are eaiser to code up in a program than others. Maybe sketch out some examples for yourself to start to get an idea of what constant numbers you might want to define in your program, and how you might like to do the math of the date subtraction...

- #6

Mentor

- 66,698

- 19,272

Why did I suggest MM/DD/YYYY format for the dates, instead of MM/DD/YY format?

To write a program in MATLAB to determine the age of a person, you can use the built-in function "datenum" to convert the person's birthdate into a serial number. Then, you can use the "today" function to get today's date, and subtract the birthdate serial number from it. Finally, divide the result by 365 to get the age in years.

The program will require the person's birthdate, which can be entered in a date format recognized by MATLAB, such as 'dd-mmm-yyyy' or 'mm/dd/yyyy'.

Yes, the program can determine the age of a person in different units by modifying the final division step. For example, dividing the result by 12 will give the age in months, and dividing by 365.25 will give the age in days.

Yes, the program can account for leap years when determining the age of a person. The "datenum" function automatically takes into account leap years, so the final result will be accurate.

No, the program cannot determine the age of a person if their birthdate is in the future. It will return a negative value, as the "today" function will be subtracted from a date in the future. This can be solved by adding a conditional statement to check if the birthdate is in the future, and in that case, subtracting the birthdate from the current date instead of the other way around.

Share:

Comp Sci
Blackjack program in javascript

- Replies
- 10

- Views
- 1K

Comp Sci
Automatic Market Research Program

- Replies
- 1

- Views
- 659

- Replies
- 5

- Views
- 980

- Replies
- 1

- Views
- 764

- Replies
- 2

- Views
- 965

- Replies
- 3

- Views
- 294

- Replies
- 1

- Views
- 888

- Replies
- 3

- Views
- 715

- Replies
- 1

- Views
- 1K

- Replies
- 2

- Views
- 724