Page 1 of 1

Can you please double check this code...

Posted: Thu Sep 06, 2012 2:13 pm
by JasonQuinn1992
Hey guys, its me again, im taking a BASIC class in college and am having trouble with it for some reason... the assignment is was given was to write a program that will request length and width of a rectangle until 0 is entered for either the length or width.


here is the code i am supposed to follow:


Initialize screen
GOSUB InputData
DO until Width = 0 OR Length = 0
GOSUB CalculateRectangle
GOSUB PrintResults
GOSUB InputData
LOOP
END

CalculateRectangle contains processing formulas
PrintResults contains printout with appropriate labels
GOSUB InputData again or it?ll be an endless loop


here is my code:


REM ******************************************************************
REM *** This program will find the length and width of a rectangle ***
REM ******************************************************************
REM
REM ***PROGRAM MAIN BODY***
CLS

GOSUB InitializeScreen
GOSUB CalculateRectangle
GOSUB PrintResults
GOSUB InputData
RETURN
END

REM ********************************
REM *** Initialize Screen ***
REM ********************************

InitializeScreen
CLS
RETURN

REM *********************************
REM *** Print Results ***
REM **********************************

InputData:
INPUT "Calculate length:$"; Calclength
INPUT "Calculate width:S"; Calcwidth
CLS
RETURN


DO UNTIL Calcwidth = 0 OR Calclength = 0


LOOP

PrintResults:

PRINT "Calculate length:$"; Calclength
PRINT "Calculate width:$"; Calcwidth
END

As you can see its different then the given but when it comes to the DO UNTIL statement I just cant input "WIDTH" I get an error, can some please help me.. I emailed my teacher but have gotten no response in a week!

Posted: Thu Sep 06, 2012 7:43 pm
by burger2227
GOSUB procedures are best placed after the end of program. Otherwise the program will progress through them and create a RETURN without GOSUB error.

Code: Select all


REM ******************************************************************
REM *** This program will find the length and width of a rectangle ***
REM ******************************************************************
REM
REM ***PROGRAM MAIN BODY***
GOSUB InitializeScreen
DO
  GOSUB InputData
  'GOSUB CalculateRectangle
  GOSUB PrintResults
LOOP UNTIL Calcwidth = 0 OR Calclength = 0
END

'place sub procedures after END of program
REM ********************************
REM *** Initialize Screen ***
REM ********************************

InitializeScreen:
CLS
RETURN

REM *********************************
REM *** Print Results ***
REM **********************************

PrintResults:
PRINT "Calculate length:$"; Calclength
PRINT "Calculate width:$"; Calcwidth
RETURN

InputData:
INPUT "Calculate length:$", Calclength
INPUT "Calculate width:S", Calcwidth
CLS
RETURN