There are several BASIC programming language statements and commands, and the best way to familiarize yourself with them and also improve your programming skills is to try some simple BASIC program examples.
With time, you will begin to master the concept of programming just by broadening your knowledge on the topic.
The program below, requests for 3 different values from a user and upon entry, the three are compared to see which is the greatest.
The result is a display of the greatest value on the screen.
Now give it a try!
Program Code10 CLS
20 INPUT "Enter the first number:"; A
30 INPUT "Enter the second number:"; B
40 INPUT "Enter the third number:"; C
50 IF A > B AND A > C THEN 90
60 IF B > A AND B > C THEN 100
70 GOTO 110
90 PRINT "The first number is the greatest:"; A
95 GOTO 130
100 PRINT "The second number is the greatest:"; B
105 GOTO 130
110 PRINT "The third number is the greatest:"; C
How The Program WorksLine 10 clears the screen with the command 'CLS' incase there is any data to be displayed alongside our results.
Line 20 to 40 will request the 3 numbers from the user by showing a display message 'Enter a Number'.
Line 50 to 60 is a BASIC conditional statement using the IF-THEN Statement. The three values entered are compared to get which is the greatest or biggest.
Line 50 gives a condition that if the value of A is greater than B and that of C, then control goes to Line 90 which is to print a result that A is the greatest of the three numbers. The next line 95 with a Goto statement after Line 90 ends the program.
Alternatively, if the above condition on line 50 is false, control goes to the next line which is line 60. Line 60 also acts as Line 50 by comparing the value of B with that of A and C, and if the condition is true, control jumps to Line 100. The next line after 100 is implemented which automatically ends the program.
If the compiler compares line 50 and 60 and they are both false, Line 70 is then implemented, since neither A nor B is greater than C.
With the logic from the program above, you can compare more numbers.
Keep in mind that the use of Line numbers as is the case in this program is optional when using qBASIC.
Conclusion:The simple steps used in the BASIC program to compare the greatest of three numbers can be employed in solving similar problems that involve comparing values or making a decision between several items. Do you want more BASIC program examples? then try one of the following listed below.
Also Read: BASIC Program to Compare The Greatest of Three Numbers