0% found this document useful (0 votes)
11 views16 pages

Adobe Scan Feb 13, 2023 (3)

The document provides an introduction to QBASIC, a beginner-friendly programming language developed in 1985, highlighting its benefits such as English-like commands and ease of use, as well as limitations like lack of structure and professional application. It covers basic programming concepts including starting a QBASIC program, using PRINT statements, debugging, and understanding constants and variables. The document serves as a guide for beginners to learn programming fundamentals using QBASIC.

Uploaded by

moumita goswami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views16 pages

Adobe Scan Feb 13, 2023 (3)

The document provides an introduction to QBASIC, a beginner-friendly programming language developed in 1985, highlighting its benefits such as English-like commands and ease of use, as well as limitations like lack of structure and professional application. It covers basic programming concepts including starting a QBASIC program, using PRINT statements, debugging, and understanding constants and variables. The document serves as a guide for beginners to learn programming fundamentals using QBASIC.

Uploaded by

moumita goswami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Introduction to

QBASIC
w w w w w A

Chapter Focus
to
Till now, we have been using computers Introduction
of QBASIC
run some applications,
the Internet or
access Benefits and Limitations
like if we a QBASIC
Program
play games. How would you Starting
and REM
Statements
or PRINT, CLS
proceed towards designing an application Constants and Variables

playing one? Statements


a game rather than LET, INPUT
and GOTO
and
Relational
Ldo es Arithmetic,
us to direct Operators
LA programming language helps
/

some specific
Logical
the hardware so as to perform
y IF-THEN-ELSE Statements

works in the way as told


tasksThe computer
by a program.
Instruction was Code.lt

Beginner's All-purpose Symbolic


abbreviation for u s e s
commo
BASIC is the became popular asht
jand quickly
developed in T964 at
Dartmouth College
released aversion ofBASIC called QBASICwith
Microsoft
English-like commands.1985,
and conventional
of the most elementary
It is one
operating system
its MS-DOS 5.0
programming languages.
Jhar a c P a
BENEFITS OF QBASIC
which are as follows:
number of benefits
QBASIC has a
for beginners.
It is a good language Be a Techie!
commands.
It has English-like
and is easy to the QBASIC
QBASIC has easy syntax download
an
Youcan easily Internet. Generally, it is
implement. softwarefrom the Download abasiczip
available as a zip file.
be fixed easily. the directory

The errors in codes can


andinstall QBASIC
to root

skills and
It provides good
logic base,
a

move over
to higher level of
concepts to
Visual Basic, C, C+t and Java.
programming using

This is an optional chapte


Teachers'Note:
LUAMITATIONS OF Q8ASIc
QRAS SIC, in spile of the several
benefits, has some limitations They are as follows
QBASIC is tot a
professional programming language
The language is not
structured.
ne s own requirement, it is hardThough it is casy toto wnte impicnc the codes for
wnte and implement
to understand and follow for others
tsaey used in real life except in the
field of cducation and training
STARTING Q8ASIC PROGRAM
To start QBASIC,double-click
on the
QB.EXE icon from the Quick Basic folder (Fig 9.1)
Figure9Shows the welcome screen of Microsoft QuickBASIC. You can press ESC Key o
vour keyboard to continue.

Deuble-click this icon e lceme te


Ricreaeft uicksIC ter inn 4.58
1965-1988
pisgh tiereeft Carguratian.
Simeltaneounly u l i a d t i s d Canada
e a Ehter ta see the uickic Survival Gaide
Peeas ESC ta elnar thia dia leg bex

Fe
91 Stcarting QBASIC Fig 92 Welcome screen of QBASIC
The main menu of the QBASIC editor
window has the following menus-File, Edit, View,
Search, Run, Debug and Options
(Fig 93).
a SE KS x
File Edit ie Search ebes Opt ien Help
htitled
Fig 93 Main menu options of QBASIC
Tostart typing a new program, click on File> New Program (Fig. 9.4).

PRINT STATEMENT C:DOCUME-11SANCHA-1


Bo Edit Uiev St

The PRINT statement helps to display a message or a value on the Neu Frogran
pen Progran.-
standard output devicethe monitor. Save S.

rint.
The general syntax of this statement is as follows: E it

PRINT [expression list][<|] where denotes


components while < and > denotes at least one component out of
optional Fig 9.4 New Program option
under File menu
the list

133
The simplest form is just the PRINT
with all other parameters excluded. This
prints a blank line and shifts the cursor
to the next line. Info Hub
If the expression list is included, then ?is the shortcut for the Print statement.
QBASc
converts? into a Print command automatica
it prints the value of the list.
The expression list can contain either
o
Any QBASIC program must end with the END
a number or a numeric expression or a statement.
A program can also be executed by
string (an alphanumeric combination typing
Shift and F5 keys together.
which is generally used as a display A printed number is always followed by a spocs
message). A positive number always nasa leading spc
I f i t contains a number, then it whereas a negative number is preceeded by
displays
the number directly. sign.
If
the message to be displayed is wider than the
If it contains a numeric expression, width of the screen, then the message is primted
then the computed value is displayed. on to the next line during display
If it contains a string expression, then
the expression should be enclosed within double quotes.
Example: Type the following PRINT commands in the editor window:

PRINT 3

PRINT

PRINT 3+5-2

PRINT COMPUTER SCIENCE"

END
Run De bug Options
Now, to see the output of these commands, you
Start Shift F
have to run this program. To run the program, click
on
estaret
Continue FS
Run> Start (Fig. 9.5).
Make E E File...
On clicking Start, you get the following output:

Fig. 9.5 Running a QBASIC program


6
COMPUTER SCIENCE
The net

The first PRINT displays


statement numeric value which is directly printed.
3 as
control ot progr
are present. However, the
statement displays a blank line as no parameters De
as the result ot
IS transfered to the next line. The
value 6 is displayed in the third line as

Finally, the 'COMPUTER SCIENCE' is displayed


evaluation numeric
ofthe expression.
1s the string attached with the PRINT statement.
Use of ; and, with the
PRINT statement
he PRINl statement if
The PRIN

sitions on theused with emicolon


semicolon ()
() or comma () displays the next print iten
or comma )
a

QBASICdivides each screen. The symbos ols "" and "" act to join to or nore prind itens
statement forc print line
forces the next item into c zones of
to sof 14spaces cach. A comma () afler the PPISNT
PRINT state be
atement, on the other e displayed in the next zone. The senicolon C) afier a
displayed
previous one. ifIf the
the PRINT a hand
PRINT statement forces the next
rces ner iten to be printed immediately afer the
stransferred to the ends witho a comma or a semicolon, thes ontr
beginning of thedswithout
he

icolon
semicolon ends the list
of
next line for further
ne for further display,
display 1ff either
e a comna o
same row. expressions, then the successive
suco PRINT statement continues in the
Example:
The stateme PRINT 1, 2,
3, 4, 5, 6
3
will display
4

The statement PRINT 1; 2, 3;


4; 5:
12 345 6
6will display
The following PRINT commands will not
give the desired output
PRINT Computer
willgive output as 0 as the double
quotes are missing Without the
quotes 'Computer is assumed
value 0.
to be a variable holding the default
PRINT 2 MG ROAD
will display 2 0 00 for the same reason as above. Note that the
commandwill be automatically changed to PRINT 2; M; G; ROAD
DEBUGGING A PROGRAM
An error in a program is known as a bug and the process of
removing all the errors after
identifying and correcting them is known as debugging, A program can run
after debugging is complete. properiy only

Ifaprogram does not give a desired output, then it must be checked for errors. errorsSyntax
are the most common
types of errors. Syntax errors arise when program codes are not written
properly. A misspelled word in a program keyword results in a syntax error. In QBASIC, a
program is read and executed line-by-line. It means that if an error is present on line 10 of a
program, the previous nine lines are read and executed without any
dificulty.
CLS COMMAND
When successive output of a program gets generated, it appears only after the previous
output.
Thus, it can becomeconfusing as to which output has been generated by the current execution

135
of the program. The CLS command to the aid in these
comes
situations. It stands for
CLear
Clear
Screen and helps us to clear all the
previous contents of the output
screen. sh
So, fresh
output can
output Ca
be generated the codes the
henceforth. The CLS can also be used between so that previous
output is erased and the future output is displayed on a fresh screen dependin ding on the
requirement.
The general syntax of this command is:
CLS [optional parameters) .

The optional parameters are beyond the reach ofthe current syllabus.

REM STATEMENT
REM stands for REMarks which are sometimes required to be gven within a program for
Detter understanding of the logic to the reader. The comments following the REM statement
are not interpreted by QBASIC. The limitation of this statement is that it should start with the
it exceeds the current
line,
Keyword and the remark should end within the current line. If
V
then the corresponding line should also start with the REM keywora.
II a remark is to be mentioned within the same line, just after the end of the current statement,
then the (apostrophe) symbol should be used instead of the REM keyword. The symbol

can also replace the REM keyword for a full line remark.
to state what the current
The REM statement may also be used at the beginning of a program
date, time and other
program iS supposed to do. The name programmer, module number,
ofthe
using the REM
details about the program are generally written at the beginning of a program
statement.

Example:
of a PRINT statement
REM This program displays the use

display a number and a string


I t will show how to

a numbe
PRINT 5 'Displaying

PRINT Computer" 'Displaying


a string

END

CONSTANTS AND VARIABLES

Constants are
the execution of a program. There
which remain unchanged during
These are fixed values constant
constants and numeric
constants-string
two types of
basically
vit ble
alphanumerie
characters
enclosed
wtt
s e q u e n c e of
constants: They refer to character set excep
a
Srng
value ofthe QBASIC
A string constant may hold any of 32767
charactcts
quotes.
Enter). It can be a sequence of a
maximum

(Carriage returm or
c a n be
adl
negative
numbers. They oi
refer to either positive or
Numeric constants: They
classified into the following types.

Integer which refers to whole numbers in the range -32768to 3276L to


in the range 21474856S
which refers to the whole numbers
Long lnteger
2147483647. or negauve
either positive
fractional numbers,
Fixed point which refers to the written in the
exponentat t
fractional numbers
Floating point which refers to the
Vaues
Variables hold varying
locations that
can

These a r e user-allocated
names given to memory
varables.
variables and numeric

Basically, there aretwo types of variables-string are


identihed by

or a string
constant. They As
a character For example,
String variables: They may hold either variable is NULL.
ofa string
afterthevariable
name. The default value detault
the S sign
constants
mentioned above. The
N u m e r i c variables: They may hold any ofthe numeric
sum.
variable is zero. For example,
value of a numeric
Variables
Rules for Naming variables:
mind while naming
rules must be kept in
The following
to 40
characters long. like_(underscore).

A variable name may be up characters


specific purpose
period(.) and s o m e
Letters, numbers,
allowed.
6, S, !, & and # are
letter.
begin with a command,

name must word may


be a
variable reserved
The reserved word. A
be a QBASIC
m u s t not
It operator name
function or a n
statement,

assignment
known as
the
LET STATEMENT variable. So, it is also
constant to a
a
statementhelps
to assign
The LET to left.
works from right
statement,
It follows:
as
statementis
LET
of the v a r i a b l e >

general syntax the


The name>
=
< c o n s t a n t :

of the
variable on

the value left-hand


value or the
< v a r i a b l e

constant name
on
[LET] and the variable
or a

is
reserved
reterred by the (either a
string

memory
space memory
space the data type
Here, a to the statements,

allocated
LET
side is =. In all the
nght-hand operator 137
assignment sides.
both
side ofthe should be the
same
on

number)
Example
LuET AS
assigns the value 5 to the numeric variable A.
variable AS
A cOMPUTRR COMPUTER to the string
assigns the string
C45
assigns the value 4.5 to the numerie vara
Now look at the following code segment
LET A5

LET B-A Info Hub


The DIM statementallows you to assio
PRINT A, B gn
to a variable
particular type of value
END QBASIC is not case sensitive. Ihis means thot
treats both upper case and lower casechar
The output of this cers
code will display inthe same way

as A 1s
assigned the value 5 and B is assigned the value of A which is also.

ne cONST
keyword allows you to declare a variable as a constant such that the value of that
variable may not be
changed throughout the program
Example:
cONST A=5

PRINT A

LET A=6

PRINT A

This code will report an error in the third line.


It is because A is defined as a 'constant' in
So, it cannot be assigned any other value. This is line 1.
useful when a programmer wants to name a
recognised constant. For example, cONST PI = 3.14.
A variable hold only one value at
can a time. Thus, only the latest value is stored and
previous value is overwritten. any

Example:
LET A=5

LET A=6

PRINT AA

This code will display 6 and not 5 as the previous value of 5 is overwritten with 6.
138
INPUT STATEMENT
IUsing the LEI Statchieht, a value
can be
given toa variable by
entering it in the coding pa
static
(sta input). So, to change the
value of the variable, the program itself has to be
for a program to be iiexible, the
code should not change changed. But,
every time the value
anged. S0, dynamic ipput must be taken needs be to

he INPUT
during the execution of program. This is
a by done
statement.Qt allows to write interactive programs by accepting keyboard
during the program execution It temporarily halts pu
from the user. the program and waits for the entry ot daa

The general syntax is as follows:

INPUT [:1°user message" I 1 listofvariables


A semicolon immediately after INPUT keeps the cursor on the same line after the user
presses
Enter Usermessage is the message that gets displayed during execution which generally tells
us what to enter. |f a semicolon is given then a question mark is
displayed at the end of the user message whereas a comma displays
the message without a question mark, The listofvariables are
Info Hub
separated by commas, to accept the input values.
too many or too few data
f
Ifa string is entered, it need not be present within quotes.is given or given
data
the input is
to with a non-matching
* a r e given, only the text between the quotes are assigned
then an message type,
error

the variable. So
" "

are not allowed in a string input. "Redo from Start iS

displayed.
Table 9.1 shows various examples of INPUT statement.

Table 9.1 INPUT statements

Message Purpose
Statement displayed on a
?
to accept a
numeric

The program waits


to A.
INPUT A entered is assigned
constant. The data
mark for a
waits without a question
ENTER A The program
to A.
INPUT
ENTER A", A numeric data. The
data is assigned
a string
data. The
STR? The program
waits with a? for after
ENTER AS. The
A$ allocated to
INPUT ENTER STR" string entered is
line
c u r s o r to stay
in the current
INPUT forces the
data.
has entered the
after the user
Some Examples of QBASIc Codes
Code: 1 Code: 2

T0 GRMS
RDM ALGo1 R226 KILOGRS

cLa CLS
zG
LET FIRS73 IMPOT zNTZR
KILOGRAMS,

LET SECOD5 100o


LET G= KG
PRIVT FIRSTSEOoD CRAMS APE
PRINTTEE EQUTVALENT
END
END
Code: 3 Code: 4
RZM STMPLE INTEREST REM SHAP

CLS CLS

INPUT ZNTER THE TEE FIRST NUEER",


PRINCIPAL", P INPOT ACCEPT
INPUT ENTER THE INPOT AcCEPT THE SECOND EER", s
RATE, R
INPUT ENTER THE LET TEMP= F
TIME",T
LET SI PRT/ 100 LET F= S

PRINTTHE SIMPLE
INTEREST IS", SI LET S = TEMP

PRINTTHE AMOUNT IS", P + SI PRINT THE FIRST NUMBER IS", F

END PRINTTHE SECOND NUMEER IS", S

END

GOTO STATEMENT USING LABEL


UE
The GOTOstatement helps to branch a program unconditionally to a desired line, The line
that is to be branched is given an identification
name, known as the label of the statement. The
label may be a number or a string followed by a colon (:). For
example,
10: PRINT A is a valid statement with the label name as 10.
L: PRINT A is a valid statement with label name as L.
The GOTO keyword is followed by a label name that transfers the control to the line
by the label name. For example, specified
GOTO 10 will transfer the control to the line with label number 10 and
display the value of A.
GOTO Lwill transfer the control to the line with label name L
and the display value of A.
140
Example:
REM USE OF GOTO WITH LABEL

CLS

INPUT ENTER A", A

GOTO E
Info Hub
without
Programming using the GOTO
10: INPUT "ENTER B", B statement

condition is not encouraged as unconditiondal


any The
GOTO 100
branching leads to unstructured programming.
E: PRINT A
frequent use of this statement in a program signifies
that the alqorithm was not designed properly and
GOTO 10 logical problems generally exist with the solution

100: PRINT B

END

In this program, first the value of A is accepted. The GOTO E statement then transfers the
control where the value of A is displayed. Next, the GOTO 10 statement is encountered which
branches to the line where B is accepted. Finally cOTO
again uncondtionally 100 transfers
the control to the PRINT B statement where the value of B is displayed and the program
terminates.

OPERATORS
Operators arecommands or symbols that perform specific arithmetic or logical operations on
data values.JThe data values on which an operator works are known as operands.An operator
can be unary (I operand) or binary (2 operands). The operators help to mathematically or
logically join group of operands to form an expression. An expression can also be a string or
numeric constant, a variable or a computed value obtained by combining constants, variables
and other expressions with operators. Operators in QBASIC can be of five types:

Arithmetic operators for performing numeric calculations

Relational operators for comparing strings and numeric values

Logical operators for logically combining or manipulating data


Functional operators

String operators
We will be studying only about the first three types.
Arithmetic Operators used for performing mathemati
numeric data
values and are
thmetic operators work on %. Table
9
gives a detailed explanation to the
Calculations. Examples include t,- / ,
functions of various arithmetic operators.
Table 9.2 Arithmetic operators
Example Result
Operator Purpose
PRINT 2+3
Addition
PRINT2-3
Subtraction
PRINT 2*3
Multiplication PRINT 5/2 2.5
Quotient of division
PRINT 52 2
division
Quotient of integer
PRINT 23
Exponent PRINT 5 MOD 2
MOD Remainder of division

same statement, thney are executed in the


When several arithmetic operators occur in the
following order:
1. Exponentiation (
2. Negation (negative numbers) Info Hub
3. Multiplication and Division (",) Dividing by zero, raising
4. zero to a negative power
Integer division (
or arithmetic overflow
5. MOD result in run-time errors.
6. Addition and Subtraction (+,) When arithmetic and
Parentheses change the order in which arithmetic operations are relational operators are
performed. Operations within parentheses are performed first. combined in one
If the operations are different and are of the same hierarchy, expression, the arithmetic
operations are always
then they are executed from left to right.
done first.

Examples:
R = 2 + 3 / 4 * 5 - 6 willdisplay-.25 and R = (2 + 3 ) / 4 * (5 6)

will display-1.25.
I fan expression has and -side-by-side then - is executed first. For example, PRINT 5 - 2

gives an output .04 and not -25.

Relational Operators
Relational operators are used for comparing two values. The result of this comparison can be
zero or non-zero. Zero denotes false while non-zero denotes true. This evaluation can be used
in a decision-making statement to decide the flow of control. Table 9.3 lists the various
relational operators.

142
Tble 9.3 Relational operators
Reational Operato Relation Expression
Equality X-Y
Inequality XY
Less than X«Y
Greater than X>Y
Less than or equal to X-Y
Greater than or equal to
The order of execution of relational operators is:,>,<, , ,
Logical Operators
Logical operators are operators that logically combine and evaluate a result according to
some pre-detined logical operations. They generate a true or a false output that may be used
for decision-making statements. Some of the logical operators in the hierarchical order are

denoted in Table 9.4

Table 9.4
Logical operators
Result
Operator Meaning
NOT Inverse Inverts the operand.
true.
Retums a true value only when both the operands are

AND Conjunction one of the operands is true.


Returns a true value when any
OR Disjunction

Examples:
PRINT 5>3 AND 2<4 will give an output-1.
PRINT 5>3 AND 2>4 will give an output O0.
-1.
PRINT 5>3 OR 2>4 will give an output
OR 2<4 will give an output-1.
PRINT 5>3

will give an output


PRINT 5-3 OR 2-4
1.
PRINT
NOT-2 will display
PRINT
NOT 3 will display-4. which we will study
later
operators
three other logical
are
and IMP
XOR, EQV

IF-THEN-ELSE STATEMENTS about need


for making
had learnt
flowcharts, we the flow -

algorithms
and
decision-making
to control
on This
the chapter
While studying
program.
e x e c u t i o n of
a statements.

the
d e c i s i o n s during
I F - T H E N - E L S E

the
incorporated
using the
c a n be
program
lt is a control flow statement that allows conditional
branching based on whether the e
is true or false. It has two basic forms: ession
1. Singlelinestatement
2 IF-THEN-ELSE-ENDIFblock

Single-line Statement
The general syntax of the single line statement is:
IF boolean expression THEN true s tmt [ELSE false_stmt]
where boolean expression is a valid expression that returns either true
falese
or

true stmt consists of the statements to be executed when the boolea.


expression is true;
false_stmt consists of the statements to be executed when the boolear
expression is false.
Here, first the boolean expression is evaluated. If the expression results in a true value
then the
control is transferred to the statement(s)
following the THEN part, whereas if the condition is
talse then the control is transferred to the
statement(s) following the ELSE part. In both the
cases, all the statements for that
part are executed sequentially. The control is transferred to
some other part on
encountering a GOTO statement.
The ELSE part is optional. If the statement has
only the true part then the statements after
THEN will be executed only when the statement is true. If it is false then the flow
of control
of the program will
go to the line following the IF statement.

Example:
IF A>B THEN PRINT A ELSE PRINT B

IF A-1 THEN A=A+1 : PRINT A

IF A>B THEN A=A+1 : PRINT A ELSE B=B+1: PRINT B

IF A >= 0 AND A < 10000 THEN PRINT WITHIN RANGE"


Info Hub
ELSE PRINT "OUT OF RANGE" The colon helps to join
multiple statements and write
IF A<10 THEN DIG=1 them in a single line.
ELSE IF A<100 THEN DIG=2

ELSE IF A<1000 THEN DIG=3 ELSE DIG=4

144
IF-THEN-ELSE-ENDIF Block
The general syntax of the block IF-THEN- ELSE is
IF boolean
expression1 THEN
[statement block-1]
(ELSEIF boolean expression2 THEN
[atatement block-2]

ELSE]
[statement block-n] ]
END IF
where
DoOLean_expression is a valid expression that returns either true or false.
statement block consists of
any number of statements on one or more lineS.
Here, the program starts by
evaluating the first boolean expression. If it is true then the
statements following the THEN
are executed and
block. If the first
the control is transferred outside the total
expression is false, the control is transferred to the ELSEIF part where thee
second expression is evaluated.
Again if this is true the statements following the THEN part is
evaluated. This process continues
and if none of the conditions are true then the statements
following the ELSE part is executed. Finally, the block ends with the END IF statement
signifying the end of IF-ELSE block.
The following points need to be noted while handling IF-THEN-ELSE block
The ELSE and ELSEIF blocks are statements
both optional. Many ELSEIF clauses can be present
within an IF block.
QBASIC scans the next word after the THEN keyword. If anything other than a
comment appears after THEN, the statement is treated as a single line IF statement.
A block IF statement must be the first statement on a line. The ELSE, ELSEIF, and
END IF parts of the statement can only have a line number line label
or preceding
them. The block must end with an END IF statement.

Example:
***********
IF A< 10 THEN
INPUT Enter a number >0 but <
10000:", A DIG 1

IF AD= 0 AND A<10000 THEN ELSEIF A<100 THEN

DIG = 2
PRINT "WITHIN RANGE"
ELSEIF A<1000 THEN
ELSE
DIG=3B
PRINT OUT OF RANGE"
ELSE
END IF ****sa******

DIG=4

END IF
a Single Line Statement
Code
Ovantages of the IF-THEN-ELSE Block over single line
IF-THEN-ELSE block s tatements have the following advantages
over
statements
They are more flexible in nature.
IF-THEN-ELSE block statements
More complex conditions can be tested using
IF-THEN-ELSE block statements.
Onger statements may be written using
Block statements lend more logic to a program.
A program written using IF-THEN-ELSE block statements is easSier to read, maintain
n

and debug.

Some Examples of QBASIC Codes Using IF-THEN-ELSE


Code: 1

REM GRADE

CLS
M2,
ZNPUT AcCEPT THE MRKS Or s sUBJECTS,
M
M M3,
LET GRADE(M1+M2 M3 M4) 4
IF GRADE<50 THEN PRINT FAIL ELSE PRINT PASS
Info Hub
END
It is a
g00d programming
Code: 2 practice to include the CLS
and REM statements in a
REM DIVISIBLE program as it adds to the

CLS legibility of the code as well


as the output.
INPUT "ENTER A NUMBER, N

IF N MOD 7 0 THEN PRINT DIVISIBLE BY 7 ELSE PRINT NOT DIVISIBLE BY 7


END
Code: 3

REM GREATER OF TWO NUMBERS -ELSEIFS>F THEN


RIEM ASsUME BOTH MIGHT BE PRINT SECOND NUMBER IS
EQUAL GREATER"
CLS ELSE

INPUT ENTER THE FIRST NUMBER F PRINT BOTH ARE EQUAL"


INPUT"ENTER THE SECOND NUMBER, s END IF

IF F> s THEN END

PRINTFIRST NUMBER IS GREATER

6
Code: 4

REM TAX BILL


ELSEIF HP <= 1000 THEN

REM UPTO 800 HORSE POWER TAX IS 1000 LET TAX = 2000

REM FROM 801 To 1000 TAX IS 2000 ELSE

REM ABOVE 1000 TAX IS 3000 LET TAX = 300o

CLS END IF

INPUT ENTER HORSE POWER OF CAR", HPi PRINT THE TAX TO BE PAID IS RS

IF HP = 800 THEN END


LET TAX= 1000

TechBytes
Constants: fixed values that remain
Program: a set ofinstructions which direct of a program
a computer to carry out a particular task unchanged during the execution
.Variables: user-allocated names given to
.BASIC: beginner's All-purpose Symbolic hold varying
locations which can
Instruction Code memory
values
Syntax: rules for writing a program and the to logically
commands therein Operators: commands that help
or arithmetically
combine a group of values
Bug: an error in a program
which the operator
.Operands: values on

Debugging: technique of removing works


errors from a program

Bits to Remember
com-
English-like
is good for beginners and has an easy
QBASIC programming language understand.
to implement and
mand syntax which is easy or a value on the monitor.
statement helps
which to display a message
PRINT is a QBASIC
? is the shortcut for the PRINT command.
during the execution of a
program.
helps to clear the
screen
CLS
comments within a program.
T h e REM statement helps to add
REM s t a t e m e n t s in a program.
should include the CLS and the
One denotes the end of a program.
statement QBASIC program that
of any
E n d is the last
and Numeric.
variables are of two types String
Constants and
initialise a variable.
T h e LET statement can
be used to
changed during the
value to a variable such that it may not be
to assign a
The CONST keyword helps
program. variables during runtime.
statement can
assign the values to
be used to
The INPUT operators.
and Logical are the major types of
Arithmetic, Relational conditional branching statements.
to implement
help
IF-THEN-ELSE statements

You might also like