QBasic Programming Exercise (WASSCE)

(Last Updated On: )

Below is a simple QBasic code that checks if a user scored 1 in both Maths and Science to determine their qualification for Class 1 or Class 2.

REM QBasic Code to Check Qualification for Class 1 or Class 2
DIM fullName AS STRING
DIM index AS INTEGER
DIM maths AS INTEGER
DIM science AS INTEGER

INPUT "Enter your Full Name:  ", fullName
INPUT "Enter Index Number: ", index
INPUT "Enter your Maths score: ", maths
INPUT "Enter your Science score: ", science

IF maths = 1 AND science = 1 THEN
    PRINT "Congratulations! You are qualified for Class 1."
ELSE
    PRINT "You are qualified for Class 2."
END IF

Explanation:

`REM stands for “remark,” and it’s used to add comments or remarks within your code. Comments are non-executable lines of text that are ignored by the QBasic interpreter when the program is run. They are used to explain the purpose or functionality of specific lines of code, making the code more understandable for other programmers (or even for yourself when you revisit the code later).

`DIM fullName AS STRING`, `DIM index AS INTEGER`, `DIM maths AS INTEGER`, and `DIM science AS INTEGER`, : Declare variables `fullName` , `index` , `maths` and `science` to store the user’s full name, index number, scores in Maths and Science, respectively.

`INPUT “Enter your Full Name: “, fullName`: Prompt the user to enter their Full Name and store it in the `FullName` variable.

`INPUT “Enter Index Number score: “, maths`: Prompt the user to enter their Index Number and store it in the `index` variable.

`INPUT “Enter Maths score: “, maths`: Prompt the user to enter their Maths score and store it in the `maths` variable.

`INPUT “Enter Science score: “, science`: Prompt the user to enter their Science score and store it in the `science` variable.

`IF maths = 1 AND science = 1 THEN`: Check if the user scored 1 in both Maths and Science.

`PRINT “Congratulations! You are qualified for Class 1.”`: If the user scored 1 in both subjects, print a congratulatory message indicating qualification for Class 1.

`PRINT “You are qualified for Class 2.”`: If the user did not score 1 in both subjects, print a message indicating qualification for Class 2.

Likes:
Views:
324

All Comments

Leave a Reply

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

error: Content is protected !!