Predeveloped Routines for BASIC
Home Up Questions, Solutions and Judges' Sheets Elementary and Junior High School BASIC Questions Predeveloped Routines for BASIC 16th  COMPETITION WINNERS

 

Winning BASIC programming

Predeveloped Routines for BASIC

If you have routines like these on a diskette when you come into the competition, and you know how to call them, then you'll be 15 minutes ahead of the next team who is trying to type them in and get them to work! AND IT IS ALL ALLOWED IN THE COMPETITION RULES

Predeveloped "Title" routine
Predeveloped "MyInput" routine
Predeveloped "AnOtherTry$" routine

The sample codes for the Title subroutine

Purpose

This is the subroutine Title will print the information about you and your team. It also print out the program name you specify when calling Title

Usage

Title subroutine take one parameter which is the program name (a string).

For example, Title("PROG1 -- ROCKET")

Code Section

 SUB Title (progname AS STRING)
  
      'Use the function CLS to clear the Screen
   CLS

         'Print out all the information
   PRINT "Predeveloped routine in use!"	'Boast to the judges that you are good
   PRINT progname$       'Print the Program name -- Change this for each program
   PRINT "by Grace Yau"  'Print the Programmer's name -- Change this before the competition
   PRINT "Team #1"       'Print the Team Number-- Change this before the competition

 END SUB  

The sample codes for the INPUT subroutine

Purpose

This is the subrountine MyInput to print out a specific prompt and check if the input from the prompt is between the minimum and maximum value. If not print out an error message. It will return a flag saying whether the input is valid or not.

Usage

MyInput take 3 parameters. The first one is a prompt message(string), the second is the lower limit (integer) of the input and the third one is the upper limit (integer) of the input.

For example, MyInput("Enter a number in this range?",2, 10) -- Ask for a number in the range 2 to 10

Code Section

 FUNCTION MyInput% (prompt AS STRING, min AS INTEGER, max AS INTEGER)

     'Keep asking the user to enter a valid value which is between the upper
     'and lower bound  
   PRINT "Predeveloped routine in use!"	'Boast to the judges that you are good  
   inputok$ = "NO" 'This controls when the DO-WHILE STOPS
   DO
  
        'Print out the prompt, the upper limit and lower limit
      PRINT prompt$; "("; min%; "-"; max%; ")";	

        'Get the input from the user
      INPUT "to use? ", ans%

        'Check if the input value is out of range
      IF (ans% > max%) THEN
         PRINT "That's too large"
      ELSEIF (ans% < min%) THEN 
	PRINT "That's too small" ;
      ELSE 'Set the flag to if there is no error in the input value 
	flag$ = "YES" 
      ENDIF 'Loop if input value is invalid out of range)   
   LOOP WHILE inputok$ = "NO"   
   MyInput%="ans%"   
END FUNCTION   
  

The sample code for the subroutine AnOtherTry

Purpose

This AnOtherTry subrountine is ask the judges if they want to try want program again. If they choose either "y","Y","yes","Yes","YES", then the program will continue, if they chose "n","N","no","No","NO", the program will quit. Otherwise it will reprompt for a valid answer.

Usage

Usage - AnOtherTry$ takes no parameters

For example

IF (AnOtherTry$( ) = "n") THEN 
	STOP

Code Section

 FUNCTION AnOtherTry$

     'Keep prompting for answer until we get "y","Y","yes","Yes","YES" or
     '"n","N","no","No","NO".  
   PRINT "Predeveloped routine in use!"	'Boast to the judges that you are good  
   DO

         'Prompt for the user see if he/she want to continue
      INPUT "Would you like to try again? (Y/N)", ans$

         'Check to see if the input is either y or n, if not reprompt
         'result is the value pass back to the main program to tell whether
         'the user want to continue or not

      IF (ans$ = "y" OR ans$ = "Y" OR ans$ = "yes" OR ans$ = "Yes" or ans$ = "YES") THEN
        result$ = "y"

      ELSEIF (ans$ = "n" OR ans$ = "N" OR ans$ ="no" OR ans$ = "No" OR ans$ = "NO") THEN
      	result$ = "n"

      ELSE
      	result$ = "unknown"
      END IF

   LOOP WHILE result$ = "unknown"

     'Set the return value be the result (y or n)
   AnOtherTry$ = result$

 END FUNCTION  

RETURN TO TOP OF PAGE

Last modified: February 11, 1999 07:51 PM by G. Yau (smith@enel.ucalgary.ca).
Copyright -- G. Yau M. R. Smith