REM Testing a function that calculates the user's age in any given year
REM And also tests to make sure that users use real numbers and future years, not past years
REM I found out that you can call subprograms from within subprograms
REM
NOMAINWIN
NOTICE "Enter the year you were born, and a year in the future."
NOTICE "This program will calculate how old you will turn in that year."
REM
REM The subprogram to ask the year you were born
GOSUB [yearBorn]
REM
REM The subprogram to ask the future year
GOSUB [futureYear]
REM
REM The function that calculates the difference
REM
NOTICE "This is how old you will be in the future: "; CALCULATEAGE(FUTUREYEAR,YEARBORN)
END
[yearBorn]
PROMPT "What year were you born?"; YEARBORN
REM
REM Another subprogram that checks YEARBORN is a real number
REM
GOSUB [checkYearBorn]
RETURN
[checkYearBorn]
WHILE YEARBORN < 1 NOTICE "You need to enter a year from sometime in the last two millenia. Numbers only." PROMPT "What year were you born?"; YEARBORN WEND RETURN [futureYear] PROMPT "Type a year in the future."; FUTUREYEAR REM REM Test to make sure a real number is used, via a subprogram REM GOSUB [checkFutureYear] REM REM Another test, to make sure that the future year is after the birth year GOSUB [checkFutureYearFuture] RETURN [checkFutureYear] WHILE FUTUREYEAR < 1 NOTICE "You need to enter a year from sometime in the last two millenia. Numbers only." PROMPT "Type a year in the future."; FUTUREYEAR WEND RETURN [checkFutureYearFuture] WHILE FUTUREYEAR <= YEARBORN NOTICE "The year you entered is before the year you were born. Enter a year after you were born." PROMPT "Type a year in the future."; FUTUREYEAR WEND RETURN FUNCTION CALCULATEAGE(FUTUREYEAR,YEARBORN) CALCULATEAGE = FUTUREYEAR-YEARBORN END FUNCTION
The program asks a user's age, and then a year in the future, and calculates how old he or she will be in the future year. It also checks for bad data -- letters and inconsistent years.
Maybe I can port it to the Web, but that would require me dusting off my old javascript skills, which I haven't tapped in about five years.
I recommend looking into RealBasic. It allows compiling for Windows, Linux, & Mac using the same source code. No need to develop source for each platform!
ReplyDelete