Days Old Algorithm Began 6/16/2010 Ethan Gomes zagaid@yahoo.com // This algorithm is used for users to input their birthday, in the format of day, month, year, and receive // an output of how many days old they are, including the current day. // This algorithm will be able to be used universally. It will still be relevant tomorrow's today. // The user will input what MONTH, DAY, and YEAR they were born, using numbers only! (EX: 10/11/1990). // The output will be rounded to a whole integar; this output will be of how many days old they are. // The output will also include TODAY'S date. That means it will count the TODAY as a day. // There are exactly 365.242199 days per 1 year; we will use this approximate in the algorithm math. // For the sake of this algorithm's accuracy, we will work with numbers to the 6th decimal place. // At the end, the number is rounded off to the nearest WHOLE NUMBER to make it user friendly. // This algorithm follows the traditional Gregorian calendar system. // This algorithm will only work with dates posted A.D. So no neanderthals allowed! // *********** BEGIN ALGORITHM *********** // 10. User inputs the month they were born. 20. User inputs the day they were born. 30. User inputs the year they were born. 40. IF month/day/year is after the current month/day/year, notify user "You have inputted a date that hasn't occurred yet." Go to line 140. 50. Multiply the number of years old by 365.242199 (exact number of days per year) to get total days old. 60. If the month inputted is BEFORE the current month, go to line 70 61. If the month inputted is AFTER the current month, go to line 80 62. If the month inputted is the SAME as the current month, go to line 90 (Essentially skip this step. You don't need to calculate month/day difference.) 70. Add the number of days from the inputted day to the end of the inputted month 71. Add the number of days in each month to the overall number days old for every whole month, from the inputted month to the current month. (accounting for leap years) 72. Add the current date to the overall number of days old. 73. Go to line 120 80. Subtract the number of days from the current day to the end of the current month. 81. Subtract the number of days in each month from the overall number days old for every whole month, from the current month to the inputted month. 82. Subtract the inputted day from the overall number days old. 83. Go to line 120 90. If the day inputted is BEFORE the current day, go to line 100 91. If the day inputted is AFTER the current day, go to line 110 92. If the day is inputted the SAME as the current day, go to line 120 100. Add the difference between the inputted day and the current day. 110. Subtract the inputted day from the current day. 111. Add the solution, from line 110, to the overall number of days old. 120. Add 1 to the overall number of days old. 121. Round to the nearest whole number. 130. Notify user "You are" and display the overall number days old, " days old." 140. End // *********** END ALGORITHM *********** // // TEST 1: Birthday is same as today BIRTHDAY: 6/16/2010 CURRENT DATE: 6/16/2010 10. Input 6 20. Input 16 30. Input 2010 40. Doesn't apply. 6/16/2010 = 6/16/2010 50. 0 * 365.242199 = 0 60. Doesn't apply. 6 = 6 61. Doesn't apply. 6 = 6 62. Applies. Skipping to line 90. 90. Doesn't apply. 16 = 16 91. Doesn't apply. 16 = 16 92. Applies. Skipping to line 120. 120. Adding 1 to the overall number of days old. (0 + 1) 121. Doesn't apply. 1 is a whole number. 130. I'm 1 days old. 140. End Works! // TEST 2: Birthday is after today BIRTHDAY: 6/17/2010 CURRENT DATE: 6/16/2010 10. Input 6 20. Input 17 30. Input 2010 40. Applies. Skipping to line 140. 140. End. Works! // TEST 3: Birthday is before today BIRTHDAY: 6/16/2008 CURRENT DATE: 6/16/2010 10. Input 6 20. Input 16 30. Input 2008 40. Doesn't apply. 6/16/2008 < 6/16/2010 50. 2 * 365.242199 = 730.484398 60. Doesn't apply. 6 = 6 61. Doesn't apply. 6 = 6 62. Applies. Skipping to line 90. 90. Doesn't apply. 16 = 16 91. Doesn't apply. 16 = 16 92. Applies. Skipping to line 120. 120. Adding 1 to the overall number of days old. (730.484398 + 1) 121. Rounding to the nearest whole number. (731) 130. I'm 731 days old. 140. End. Works! // TEST 4: Birthday is a leap day (Feb. 29th) BIRTHDAY: 2/29/2000 CURRENT DATE: 6/16/2010 10. Input 2 20. Input 29 30. Input 2000 40. Doesn't apply. 2/29/2000 < 6/16/2010 50. 10 * 366.242199 = 3662.421990 60. Applies. Skipping to line 70. 2 < 6 70. 0 + 29 = 29 71. 31 + 30 + 31 = 92 (accounting March, April, May) 72. 3662.421990 + 92 = 3454.421990 73. Applies. Going to line 120. 120. Adding 1 to the overall number of days old. (3454.421990 + 1) 121. Rounding to the nearest whole number. (3455) 130. I'm 3455 days old. 140. End. Works!