Skip to main content

Qbasic code for a simple calculator

CLS
SCREEN 13
PRINT "CALCULATOR-"
PRINT "ENTER YOUR EXPRESSION"
PRINT "EXAMPLE-58 * 20"
PRINT "THE TERMS SHOULD BE SEPARATED BY SPACE OR ERROR WILL OCCUR"
INPUT "ENTER YOUR EXPRESSION-"; EXP$
EXP$ = EXP$ + " "
INDEX = 1
DIM TERMS(3) AS INTEGER
FOR I = 1 TO LEN(EXP$)
    CURRENTTOKEN$ = MID$(EXP$, I, 1)
    IF CURRENTTOKEN$ = " " THEN
        IF INDEX = 2 AND OPERATION$ = "" THEN
            OPERATION$ = TERMCURRENT$
        ELSE
            TERMS(INDEX) = VAL(TERMCURRENT$)
            INDEX = INDEX + 1
        END IF
        TERMCURRENT$ = ""
    ELSE
        TERMCURRENT$ = TERMCURRENT$ + CURRENTTOKEN$
    END IF
NEXT I
SELECT CASE OPERATION$
    CASE "+"
        R = TERMS(1) + TERMS(2)
    CASE "*"
        R = TERMS(1) * TERMS(2)
    CASE "-"
        R = TERMS(1) - TERMS(2)
    CASE "/"
        R = TERMS(1) / TERMS(2)
    CASE "%"
        R = TERMS(1) MOD TERMS(2)
    CASE "^"
        R = TERMS(1) ^ TERMS(2)
END SELECT
PRINT TERMS(1); OPERATION$; TERMS(2); "="; R

Comments

Popular posts from this blog

electronic configuration of all elements in SPDF format

Element Electrons Electronic Configuration Hydrogen (H) 1 1s 1 Helium (He) 2 1s 2 Lithium (Li) 3 1s 2  2s 1 Beryllium (Be) 4 1s 2  2s 2 Boron (B) 5 1s 2  2s 2  2p 1 Carbon (C) 6 1s 2  2s 2  2p 2 Nitrogen (N) 7 1s 2  2s 2  2p 3 Oxygen (O) 8 1s 2  2s 2  2p 4 Fluorine (F) 9 1s 2  2s 2  2p 5 Neon (Ne) 10 1s 2  2s 2  2p 6 Sodium (Na) 11 1s 2  2s 2  2p 6  3s 1 Magnesium (Mg) 12 1s 2  2s 2  2p 6  3s 2 Aluminum (Al) 13 1s 2  2s 2  2p 6  3s 2 3p 1 Silicon (Si) 14 1s 2  2s 2  2p 6  3s 2 3p 2 Phosphorous (P) 15 1s 2  2s 2  2p 6  3s 2 3p 3 Sulfur (S) 16 1s 2  2s 2  2p 6  3s 2 3p 4 Chlorine (Cl) 17 1s 2  2s 2  2p 6  3s 2 3p 5 Argon (Ar) 18 1s 2  2s 2  2p 6  3s 2 3p 6 Potassium (K) 19 1s 2  2s 2  2p 6  3s 2 3p 6  4s 1 Calcium (Ca) 20 1s 2  2s 2  2p 6  3s 2 3...

DOWNLOAD AVENGERS:ENDGAME

IF YOU WANT TO DOWNLOAD  AVENGERS:ENDGAME (HINDI) THEN FOLLOW THE LINK BELOW TO DOWNLOAD AVENGERS:ENDGAME---- Click here

Most satisfying wallpapers