07-29-2003, 10:47 PM
I am making a program that adds strings and yadda yadda. this was made before but i felt like making one.
Heres the add part. (this is all i have done for the time being)
if you have a problem just ask. I accept compliments and complaint but i tjhink i will listen to the complements more
edit: found mistake and fixed
edit: added comments
edit: fixed problem when adding 0 and 0
Heres the add part. (this is all i have done for the time being)
Code:
DECLARE FUNCTION add$ (n1$, n2$)
FUNCTION add$ (n1$, n2$)
IF VAL(n1$) > VAL(n2$) THEN b1$ = n1$ ELSE b1$ = n2$ 'Finds the biggest number
'###Following 2 lines make the lengths the same###
IF LEN(n1$) < LEN(n2$) THEN n1$ = STRING$(LEN(n2$) - LEN(n1$), "0") + n1$
IF LEN(n2$) < LEN(n1$) THEN n2$ = STRING$(LEN(n1$) - LEN(n2$), "0") + n2$
DIM num(LEN(b1$) + 1, 3) 'Dims an array
FOR i = LEN(b1$) + 1 TO 2 STEP -1 '\
num(i, 1) = VAL(MID$(n1$, i - 1, 1)) '|===Puts numbers
num(i, 2) = VAL(MID$(n2$, i - 1, 1)) '|===into array
NEXT '/
'the following 4 lines add.
FOR x = LEN(b1$) + 1 TO 1 STEP -1
num(x, 3) = num(x, 3) + num(x, 2) + num(x, 1)
IF num(x, 3) > 9 THEN num(x - 1, 3) = 1: num(x, 3) = VAL(LTRIM$(RIGHT$(STR$(num(x, 3)), 1)))
NEXT x
'Num$ = the added numbers
FOR x = 1 TO LEN(b1$) + 1
num$ = num$ + LTRIM$(STR$(num(x, 3)))
NEXT x
'Removes "0"s off the front
DO
z = z + 1
IF z > LEN(num$) THEN EXIT DO
IF MID$(num$, z, 1) = "0" THEN num$ = RIGHT$(num$, LEN(num$) - 1) ELSE EXIT DO
LOOP
add$ = num$
END FUNCTION
if you have a problem just ask. I accept compliments and complaint but i tjhink i will listen to the complements more
edit: found mistake and fixed
edit: added comments
edit: fixed problem when adding 0 and 0