Write program in MATLAB to determine age of person

Click For Summary

Discussion Overview

The discussion revolves around constructing a MATLAB program that calculates the number of days a person has been alive based on user input for their birthday and the current date. The scope includes programming concepts, syntax, and initial problem-solving strategies for beginners in programming.

Discussion Character

  • Homework-related
  • Exploratory
  • Technical explanation

Main Points Raised

  • Some participants express a lack of experience in programming and seek guidance on how to start writing the MATLAB program.
  • One participant suggests listing the number of days in each month and year as a foundational step for the program.
  • Another participant emphasizes the importance of creating pseudocode to outline the program's logic before diving into actual coding.
  • Resources from Mathworks are shared as helpful materials for learning MATLAB.
  • A participant poses a question regarding the choice of date format (MM/DD/YYYY) over a two-digit year format (MM/DD/YY), prompting further exploration of date handling in programming.

Areas of Agreement / Disagreement

Participants generally agree on the need for foundational programming steps and resources, but there is no consensus on specific programming approaches or solutions to the problem presented.

Contextual Notes

Some participants express uncertainty about syntax and programming concepts, indicating a reliance on external resources and the need for clarification on basic programming principles.

Who May Find This Useful

Beginners in programming, particularly those using MATLAB for engineering applications, may find this discussion useful for understanding initial programming strategies and resources.

bbarke00
Messages
6
Reaction score
0
1. Construct a program that will ask the user the current date and his/her birthday and display the number of days
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
 
Physics news on Phys.org
bbarke00 said:
1. Construct a program that will ask the user the current date and his/her birthday and display the number of days
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)...
 
I apologize for the absence of an attempt, but I don't even know what syntax to use or where to start. I've never programmed before and this is my first programming class for engineering. My professor said he would show us but I wanted to struggle a little bit first.
 
bbarke00 said:
I apologize for the absence of an attempt, but I don't even know what syntax to use or where to start. I've never programmed before and this is my first programming class for engineering. My professor said he would show us but I wanted to struggle a little bit first.

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...
 
BTW, Quiz Question for you:

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

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 22 ·
Replies
22
Views
4K
Replies
16
Views
3K
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K