The program for PP5.3:
! PP5.3 is nearly the same as PP5.2, below, except you are to
! test the program using dates 11-15-85,12-8-86,11-7-83,3-1-09.
! Enter these as a data statement and loop through the dates.
The old header for PP5.2:
! Ask a user to enter a date in MM-DD-YY format.
! For example, 1-25-99 is January 25, 1999
! Separate the numbers representing the month, date, and year.
! Display each number with an appropriate label.
! For example, print "The date you entered is January 25, 1999."
! for the given example. Assume the twentieth century.
! Run do trace, slow (month$,day$,year$)
DO while more data
LET count = count + 1
READ when$
!PRINT "Please enter a date as MM-DD-YY, eg. 1-30-87."
!PRINT "Use only dates in the twentieth century."
!LINE INPUT when$ !comment out to use data input from loop
PRINT "The date entered is"; " "; when$
CALL month (when$, month$)
CALL day (when$, day$)
CALL year (when$, year$)
PRINT "Rewriting the date gives ";month$;" ";day$;",";year$
LOOP
DATA 11-15-85,12-8-86,11-7-83,3-1-09
PRINT "The number of dates entered by the data statement is "; count
END
SUB month (When$, month$)
LET month$ = When$[1 : pos(When$,"-") - 1]
IF month$ = "1" then LET month$ = "January"
IF month$ = "2" then LET month$ = "February"
IF month$ = "3" then LET month$ = "March"
IF month$ = "4" then LET month$ = "April"
IF month$ = "5" then LET month$ = "May"
IF month$ = "6" then LET month$ = "June"
IF month$ = "7" then LET month$ = "July"
IF month$ = "8" then LET month$ = "August"
IF month$ = "9" then LET month$ = "September"
IF month$ = "10" then LET month$ = "October"
IF month$ = "11" then LET month$ = "November"
IF month$ = "12" then LET month$ = "December"
END SUB
SUB day (When$, Day$)
LET Day$ = When$[pos(When$,"-") + 1 : posr(When$,"-") - 1 ]
END SUB
SUB year (When$, Year$)
LET Year$ = When$[posr(When$,"-") + 1 : 100]
LET Year$ = "19" & Year$
END SUB
The output from this program is:
The date entered is 11-15-85
Rewriting the date gives November 15,1985
The date entered is 12-8-86
Rewriting the date gives December 8,1986
The date entered is 11-7-83
Rewriting the date gives November 7,1983
The date entered is 3-1-09
Rewriting the date gives March 1,1909
The number of dates entered by the data statement is 4