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!
Can you please double check this code...
-
- Coder
- Posts: 42
- Joined: Mon Sep 03, 2012 4:32 pm
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
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
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0