Posts: 3,343
Threads: 83
Joined: Mar 2003
Damn your rawhide Hex!!! :evil: You took my limelight!! I was gonna draw it out on relsoft!!
Oh, and by the way, the curvy x I think is only possible if you copy and paste from MS Word (small letter chi in greek symbols). There may be a code, Hex here is your chance to shine again! (ps 03c7, Alt-X doesn't work here)
Posts: 749
Threads: 4
Joined: Jun 2002
Rel, no time for today nor tomorrow. Maybe this monday. (just be sure to pop up between 13:00 and 15:00 hrs. of your local time) :roll:
img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
Posts: 3,368
Threads: 195
Joined: Jan 2003
Hey hey, back to the subject: for part of a project I needed to make an arithmetic evaluator. It doesn't do any variable solving though. It just evaluates the expression. (now I have to make this into LISP. But I can't think in LISP, so I didn't.)
(edit: all fixed.)
Code:
DECLARE FUNCTION reduce.string$ (string1$)
CLS
INPUT "Enter expression: ", string1$
IF string1$ = "" THEN string1$ = "(6 * 7) + (8 * 9)"
PRINT string1$ + " = ";
PRINT
string1$ = "(" + string1$ + ")"
DO
string1$ = reduce.string$(string1$)
IF INSTR(string1$, "(") = 0 THEN EXIT DO
LOOP
SLEEP
SYSTEM
FUNCTION reduce.string$ (string1$)
DO
IF string1$ = "" THEN EXIT DO
start.p% = INSTR(string1$, "(")
end.p% = INSTR(string1$, ")")
IF start.p% = 0 THEN EXIT DO
string2$ = string2$ + MID$(string1$, 1, start.p%)
string1$ = MID$(string1$, start.p% + 1, LEN(string1$) - start.p%)
LOOP UNTIL INKEY$ <> ""
end.s1% = INSTR(string1$, ")") - 1
string2$ = MID$(string2$, 1, LEN(string2$) - 1)
string3$ = MID$(string1$, end.s1% + 2, LEN(string1$) - end.s1%)
string1$ = MID$(string1$, 1, end.s1%)
'first find all * and /
DO
dm.exists% = 0
DO
div.exists% = INSTR(string1$, "/ ")
mult.exists% = INSTR(string1$, "* ")
IF div.exists% + mult.exists% <> 0 THEN
IF div.exists% > mult.exists% THEN op$ = "/": op.exists% = div.exists% ELSE op$ = "*": op.exists% = mult.exists%
GOSUB replace.string
dm.exists% = 1
ELSE
EXIT DO
END IF
LOOP UNTIL INKEY$ <> ""
LOOP UNTIL dm.exists% = 0
'then find all + and -
DO
dm.exists% = 0
DO
sub.exists% = INSTR(string1$, "- ")
add.exists% = INSTR(string1$, "+ ")
IF sub.exists% + add.exists% <> 0 THEN
IF sub.exists% > add.exists% THEN op$ = "-": op.exists% = sub.exists% ELSE op$ = "+": op.exists% = add.exists%
GOSUB replace.string
dm.exists% = 1
ELSE
EXIT DO
END IF
LOOP UNTIL INKEY$ <> ""
LOOP UNTIL dm.exists% = 0
reduce.string$ = string2$ + string1$ + string3$
EXIT FUNCTION
replace.string:
num1$ = "": num2$ = ""
i = op.exists% - 2
DO
st$ = MID$(string1$, i, 1)
IF INSTR("0123456789", st$) <> 0 THEN
num2$ = st$ + num2$
ELSE
EXIT DO
END IF
i = i - 1
IF i = 0 THEN i = i + 1: EXIT DO
LOOP
j = i
i = op.exists% + 2
DO
st$ = MID$(string1$, i, 1)
IF INSTR("0123456789", st$) <> 0 THEN
num1$ = num1$ + st$
ELSE
i = i - 1
EXIT DO
END IF
i = i + 1
IF i > LEN(string1$) THEN i = i - 1: EXIT DO
LOOP
SELECT CASE op$
CASE "+": num3$ = LTRIM$(STR$(VAL(num1$) + VAL(num2$)))
CASE "-": num3$ = LTRIM$(STR$(VAL(num2$) - VAL(num1$)))
CASE "*": num3$ = LTRIM$(STR$(VAL(num1$) * VAL(num2$)))
CASE "/": num3$ = LTRIM$(STR$(VAL(num2$) / VAL(num1$)))
END SELECT
string1$ = MID$(string1$, 1, j - 1) + num3$ + MID$(string1$, i + 1, LEN(string1$) - i)
PRINT string2$ + string1$ + string3$
RETURN
END FUNCTION
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.