Practice Program 5.2:

(Note: the use of subroutines is discussed in Chapter 7)

 

! 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$). Copy (^C) the command, and paste (^V) in the Command

! Window, which appears with ^j.

 

PRINT "Please enter a date as MM-DD-YY, eg. 1-30-87."

PRINT

PRINT "Use only dates in the twentieth century."

PRINT

LINE INPUT when$

PRINT

PRINT "The date you entered is"; " "; when$

PRINT

CALL month (when$, month$)

CALL day (when$, day$)

CALL year (when$, year$)

PRINT "This date may also be written as ";"month$";" ";"day$";",";" ";"year$"

PRINT

PRINT "In your case, the date would be ";month$;" ";day$;",";year$

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 might be:

Please enter a date as MM-DD-YY, eg. 1-30-87.

 

Use only dates in the twentieth century.

 

? 10-9-98

 

The date you entered is 10-9-98

 

This date may also be written as month$ day$, year$

 

In your case, the date would be October 9,1998