write an algorithm for age calculation
Answers
Step-by-step explanation:
Simply by subtracting the birth date from the current date. This conventional age formula can also be used in Excel. The first part of the formula (TODAY()-B2) returns the difference between the current date and date of birth is days, and then you divide that number by 365 to get the numbers of years.
Answer:
--SET CURRENT YEAR, MONTH, AND DAY TO VARIABLES Y, M, D
set {year:y, month:m, day:d} to (current date)
--QUERY USER TO ENTER THEIR BIRTHDAY INFORMATION
set BirthdayDay to text returned of (display dialog "Enter Day of Birth" default answer "")
set BirthMonth to (choose from list {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"} with prompt "Please Choose Birthday Month")
set BirthYear to text returned of (display dialog "Enter four digit birth year" default answer "")
--TURN USER INFORMATION INTO DATE FORMAT
set UserBirthDay to BirthMonth & " " & BirthdayDay & "," & BirthYear as string
set Birthdate to date UserBirthDay
--CONVERT MONTH INTO A NUMBER (INTEGER)
set theMonthNumber to ((month of Birthdate as integer) as string)
--CALCULATE USERS AGE AND WHEN THE USERS NEXT BIRTHDAY IS
set UserAge to y - (year of Birthdate)
set daysleft to (day of Birthdate) - d
set monthleft to (theMonthNumber) - m
--CHECK IF DAYS LEFT ARE NEGATIVE NUMBER AND CONVERT INTO WHOLE NUMBER
if daysleft < 0 then
set daysleft to daysleft / -1 as integer
end if
--CHECK IF MONTH HAS ALREADY PAST
if monthleft < 0 then
set monthleft to monthleft + 12
else
set UserAge to UserAge - 1
end if
--SET TEXT TO SHOW USER WHEN BIRTHDAY IS
set BirtdayInfo to "You are currently...
" & UserAge & " years old
" & "There are...
" & monthleft & " months and
" & daysleft & " days " & "left until your birthday!"
--CHECK TO SEE IF TODAY IS THE USERS BIRTHDAY
if monthleft = 0 and daysleft = 0 then
set BirtdayInfo to "HAPPY BIRTHDAY!"
end if
Step-by-step explanation: