Skip to content

Instantly share code, notes, and snippets.

@svineet
Created September 30, 2012 07:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save svineet/3806145 to your computer and use it in GitHub Desktop.
Save svineet/3806145 to your computer and use it in GitHub Desktop.
QBASIC Code for a simple calculator program
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
@blixxful
Copy link

31 SELECT CASE OPERATION$
this is trowing error, illegal between select case and case
what is the problem
i am a beginner

@blixxful
Copy link

how do i fix the error in line 31
illegal between select case and case

@Vulture2009
Copy link

how do i fix the error in line 31 illegal between select case and case

did u put a space between two characters?

WRONG : 2+2
RIGHT : 2 + 2

@Mmaxbhai
Copy link

Mmaxbhai commented Mar 2, 2023

CLS

INPUT "ENTER ANY NUMBER"; N

A N

S = 0

WHILE N <> 0

RN MOD 10

S S 10+ R

N = N \ 10

WEND

IF A = S THEN

PRINT A; "IS PALINDROME"

ELSE

PRINT A; "IS NOT PALINDROME"

END IF

END

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment