Write a program in Qbasic to display
*
Answers
Explanation:
QBasic Tutorial 1
Load up QBasic and then press "ESCAPE" to clear the info dialog box. You should see a empty blue screen with the cursor flashing in the top left corner. The first program we are going to write will be very simple. It will display a message on the screen. Type the following:
PRINT "Hello World"
Once you have typed the very small program into the main editor you are ready to run the program. In QBasic you can run a program in a number of ways. The easiest method is by pressing F5. Do that now. You will find that the screen clears to black and prints the word "Hello World" in the top left corner.
Sometimes if you load QBasic from DOS you will find that the remains of the commands are left in the background. For example C:>QBasic would be left in the background if you loaded it from DOS. You don't need to worry about this as the CLS command will sort your problems out. CLS command will Clear the Screen for you before doing the next operation. For example type the following in and press F5.
CLS
PRINT "Hello World"
Once you run the program you will find that access information left behind will be cleared away and you will be left with a black screen with "Hello World" printed in the corner. "PRINT" and "CLS" command's are available in my Reference section.
With the "PRINT" statement you can have as many as you like in a program. For example type the following:
CLS
PRINT "Hello World"
PRINT "Hello Again"
PRINT "Goodbye!"
This will print all three lines on the screen one after the other. So far you should of not had any error's. If you had it might of been one of the following:
PRINT ""Hello World""
You cannot have no more than two inverted commas(") in any print statement.
CL S
This command should read CLS not CL S.
CLS
PRINT "Hello World
Don't miss the inverted comma from the end or the beginning of the print statement.
Here is a handy tip. Move the cursor up to the end of the "PRINT" statement. It does not matter which "PRINT" statement. Press F1. A Help file will be displayed containing information of that particular statement. Very helpful if you get stuck on a particular command.
So far you have learned two brand new commands. Being "PRINT" and "CLS". Now I will introduce you to two further commands. These are called "FOR" and "NEXT". These commands are very useful. To clear the previous program hold down ALT and then press F. Follow on screen instructions until you start with a fresh page.
Now type the following program exactly how it is shown below.
CLS
FOR i=1 to 10
PRINT "Hello World"
NEXT i
Press F5 to run the program and see what happens. You will find that the word "Hello World" is printed 10 times down the screen. Now let's break down the program and see how it works.
CLS
Clears the screen of any leftover rubbish which might be around.
FOR i=1 to 10
This is the interesting bit. "i" is a variable, variables are talked about in tutorial 2, the variable will store a value. To start with the variable will hold the value of 1. Everytime the "NEXT i" statement is reached the program will check to see if the variable "i" is 10. If it is not 10, then the program will continue and jump back to where the "FOR" command was. It is like a loop, everytime the "i" variable is not 10 it will jump back and increase the number by 1. So if you set the "FOR" loop to 20, "NEXT" will check to see if "i" has reached 20. For example:
1,2,3,4,5,6,7,8,9,10 STOP!!!!
Answer:
Cls
Print"*"
End
Explanation:
Cls to clear the screen
Print"*" to print *
End to end the program...
Simple