How to Write a Program that is like a calculator in QBasic ??

Answers (1)

Below is a code to create a calculator program in Qbasic that asks the user to enter 2 numbers and then asks the user to choose from options to add, subtract, multiply or divide the two numbers. Input validation has to be used in this code to identify if the user has entered the correct data. This program will also ask users to continue or exit in the end after the results. 

  • Start your Qbasic program 
  • Enter the code 

1 CLS
COLOR 7
DIM NUM1 AS SINGLE
DIM NUM2 AS SINGLE
PRINT TAB(30); "BASIC CALCULATOR "
DO WHILE REP$ <> "N"
    PRINT
    INPUT "FIRST NUMBER"; NUM1
    PRINT
    INPUT "OPERATOR"; OPERATOR$
    PRINT
    INPUT "SECOND NUMBER"; NUM2
    PRINT

    CALL OPERAN(NUM1, OPERATOR$, NUM2) 'FOR OPERATORS

    INPUT "TO EXIT PRESS (N), TO CONTINUE PRESS ENTER"; REP$
    REP$ = UCASE$(REP$)
    GOTO 1
LOOP

COLOR 4

SUB OPERAN (NUM1, OPERATOR$, NUM2)
COLOR 2
PRINT NUM1; OPERATOR$; NUM2; "=";
IF OPERATOR$ = "+" THEN
    PRINT NUM1 + NUM2
ELSE IF OPERATOR$ = "-" THEN
        PRINT NUM1 - NUM2
    ELSE IF OPERATOR$ = "*" THEN
            PRINT NUM1 * NUM2
        ELSE IF OPERATOR$ = "/" THEN
                PRINT NUM1 / NUM2
            ELSE
                COLOR 4
                PRINT " YOU HAVED ENTERED A WRONG OPERATOR SIGN"
                BEEP
            END IF
        END IF
    END IF
END IF
PRINT
CALL FOOTB


END SUB

SUB FOOTB
COLOR 4
COLOR 7

END SUB

  • Press "F5" to run the program.

 

Preparation Products

Knockout NEET May 2023 (Easy Installments)

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 5499/-
Buy Now
Knockout JEE Main April 2021 (One Month)

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 14000/- ₹ 4999/-
Buy Now
Knockout NEET Aug 2021 (One Month)

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 14000/- ₹ 4999/-
Buy Now
Knockout JEE Main May 2021

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 22999/- ₹ 9999/-
Buy Now
Knockout NEET Aug 2021

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 22999/- ₹ 9999/-
Buy Now
Boost your Preparation for JEE Main with our Foundation Course
 
Exams
Articles
Questions