Computer Science Education | Programming Language Tutorials For Beginners

QBASIC TUTORIAL 11 - The QBasic Challenge (End)

Problem 1:
Write a program which will be able to compute a simple mathematical calculation that can Add, Divide, Multiply & Subtract a given numbers.

Solution:
DIM Num1 AS SINGLE
DIM Num2 AS SINGLE
DIM Sel AS STRING

DO
    CLS

    PRINT
    INPUT "Enter First Number: ", Num1
    INPUT "Enter Second Number: ", Num2

    PRINT
    PRINT "A) Add"
    PRINT "D) Divide"
    PRINT "M) Multiply"
    PRINT "S) Subtract"
    INPUT "Enter Selection: ", Sel
    Sel = UCASE$(Sel)

    PRINT
    SELECT CASE Sel
        CASE "A"
            PRINT Num1; "+"; Num2; "="; Num1 + Num2
        CASE "D"
            PRINT Num1; "/"; Num2; "="; Num1 / Num2
        CASE "M"
            PRINT Num1; "*"; Num2; "="; Num1 * Num2
        CASE "S"
            PRINT Num1; "-"; Num2; "="; Num1 - Num2
        CASE ELSE
            PRINT "Wrong Selection"

    END SELECT

    PRINT
    INPUT "Do you want to make another calculation (Y/N): ", Sel
    Sel = UCASE$(Sel)

LOOP UNTIL Sel = "N"


OUTPUT:


Problem 2:
You are a computer programmer hired by a movie theater. Your job is to create a QBasic program that will determine the price of a theatre ticket based on the customer’s age. 

The program must be able to input the customer’s age then set the conditions so the price is determined as follows:

Age 0-4         (Child)         Price=$2
Age        5-18      (Student)    Price=$10
Age 19-64 (Adult)         Price=$15
Age > 64       (Senior) Price=$8

After the age is determined, the program must print the correct price of the ticket on the screen.


Solution:
DIM Age AS INTEGER
DIM Enquiry AS STRING

DO
    CLS

    PRINT
    INPUT "Enter the Age : ", Age

    PRINT
    PRINT "Age 0 TO 4 = Child"
    PRINT "Age 5 TO 18 = Student"
    PRINT "Age 19 TO 64 = Adult"
    PRINT "Age > 64 = Senior"

    PRINT
    SELECT CASE Age
        CASE 0 TO 4
            PRINT "Child Category = $2"
        CASE 5 TO 18
            PRINT "Student Category = $10"
        CASE 19 TO 64
            PRINT "Adult Category = $15"
        CASE IS > 65
            PRINT "Senior Category = $8"

    END SELECT

    PRINT
    INPUT "Do you wish to make another enquiry (Y/N): ", Enquiry
    Enquiry = UCASE$(Enquiry)

LOOP UNTIL Enquiry = "N"


Output:
When age entered is : 3

When age entered is : 29

This is where i will be ending the QBasic tutorial for beginners. The next Programming language tutorials will be starting soon. Try commenting after going through the tutorials, it goes a long way. Thanks. 😁

Share:

No comments:

Post a Comment

Popular Posts

Elitcode - Learning Start Here

Elitcode Blog Archive