Step 5 – finding the full date of birth
A linear search can be used to find an item in a list of anything, so long as there's a sensible order for the things in the list.
You just need to get the list of items right.
What if the program could find your date of birth? Not just the month, but the day and the year as well?
- This needs 3 different lists: one for months; one for years (but when will you start and end?) and one for days (1 to 31 I suppose)
- Then you'd need to work through each list using a while loop. It would probably be easiest to do this three times
- And then at the end you can tell the user when their birthday is.
- This is a bit more complex and you probably won't get it right first time. Don't worry about that!
Some hints:
- I suppose you don't need a list for the dates. Those are just numbers like they were in the basic linear search
- be careful of your variable names. It could get a bit messy (guesses in particular)
- I don't think it matters that February only has 28 days (or 29 in a leap year). The search will find the date before you get to 30 if someone is born in February
Good luck
That's this puzzle done. What else could you use a linear search for?