QBASIC – Input a number and display it

The example below takes a number from a user as input and displays it.

' Program to input a number and display it
CLS
INPUT "Enter a number";a
PRINT "The number you entered is ";a
END

Explanation:

The first line starting with a single quote(‘) is a comment which is not interpreted by the QBASIC interpreter. Comments are very useful to remember what the statements are being used for in the program or to know what the piece of code does when executed.

The second line is a CLS to clear the output screen.

The third line uses an INPUT statement with a message inside double quotes (“). The number entered by the user is stored in variable a.
Note the difference between single and double-quotes.

The fourth line uses the PRINT statement to display a message along with the value in the variable a.

Leave a Comment

Your email address will not be published. Required fields are marked *