Ok, qbasichelp, I hope this is not for homework, because we're not supposed to do your homework for you.
Anyway, since some of the guys gave you a hard time, I thought I'd help you. There's no such thing a a simple calculator. There's too many factors like handling negative numbers, numbers with decimals, validating the numbers, divide by zero considerations, etc. But, I tried to keep as simple as possible, but functional.
Code:
defint a-z
dim ValA as double
dim ValB as double
dim Ans as double
const DecimalPlaces = 3 'Maximum decimal places allowed
print "Value.A Operator Value.B"
print
geta:
print "Enter Value.A";
input z$
z$=ltrim$(rtrim$(z$))
if z$="-1" then system
'Note: If you really need -1, then enter -1. that is -1 and a decimal.
if left$(z$,1)="-" then
signa=-1
z$=mid$(z$,2)
else
signa=1
end if
gosub Numdec
if NumValid=0 then
print "Invalid Value.A"
goto geta
end if
ValA=val(z$)
ValA=ValA*signa
getop:
print "Enter the Operator (+-*/)";
input op$
if instr("+-*/",op$)=0 or len(op$)<>1 then
print "Invalid Operator"
goto getop
end if
getb:
print "Enter Value.B";
input z$
z$=ltrim$(rtrim$(z$))
if left$(z$,1)="-" then
signb=-1
z$=mid$(z$,2)
else
signb=1
end if
gosub Numdec
if NumValid=0 then
print "Invalid Value.B"
goto getb
end if
ValB=val(z$)
ValB=ValB*signb
'Ok, we have all the parameters, now compute.
divzero=0
SELECT CASE op$
CASE "+"
Ans = ValA + ValB
CASE "-"
Ans = ValA - ValB
CASE "*"
Ans = ValA * ValB
CASE "/"
if ValB<>0 then Ans = ValA / ValB else divzero=1
CASE ELSE
END SELECT
if divzero=1 then
print "ERROR: Divide by zero"
else
print "Answer = ";Ans
end if
print
goto geta
REM *
REM *** CHECK FOR STRICTLY NUMERIC, NO NULL, ALLOW A DECIMAL POINT.
REM *
Numdec:
NumValid=0 'Init to False
W$=Z$
IF W$="" THEN RETURN
ZZP=INSTR(W$,".")
IF ZZP>0 THEN
MID$(W$,ZZP,1)="0"
IF ZZP < LEN(W$)-DecimalPlaces OR INSTR(W$,".") THEN RETURN
END IF
FOR ZZ = 1 TO LEN(W$)
A=ASC(MID$(W$,ZZ,1))
IF A<48 OR A>57 THEN RETURN
NEXT ZZ
NumValid=-1 'True
RETURN
If it's not clear, just ask me.
*****