top of page

Age Calculator Extended

This program is the same as the "Age Calculator Program", except that it prompts the user for the current year and their birth year. It then takes the persons birth year and the current year and calculates their age, and works out their age if they were born 10 years earlier.



Variables Program Example 2

Create some variables and set their values.


prog_vars =

d/name "Fred" -- name text var with default value

d/birth_year 1972 -- year of birth

d/current_year 2020 -- the current year

d/age 0 -- age in years

d/message1 "If you were born 10 years earlier"


prog_start =

print " -------------- "

print "Age Program Begin 2"


prog_loop =

-- Get the current year from the user

print "Enter the current year? "

getline -> /current_year

-- Get their birth year

print "Enter your birth year? "

getline -> /birth_year

-- Work Out their age

sub /current_year /birth_year -> /age

print "Hi /name you are /age years old"

-- Subtract 10 years from their birth year and recalc.

sub /birth_year 10 -> /birth_year

print "New birth year /birth_year"

-- Work Out their newage

sub /current_year /birth_year -> /age

-- Use /message1 to hold the message so the lines not too long.

print "/message1 you would be /age years old"

print "Done exiting now!"



prog_stop =



bottom of page