QB / QB64 Discussion Forum      Other Subforums, Links and Downloads
 Return to Index  

oops, forgot the last carry

April 23 2011 at 12:51 PM
lawgin  (no login)


Response to If only adding positive integers...

INPUT "2 integers to add ", a$, b$
DO UNTIL a$ = "" AND b$ = ""
c = VAL(RIGHT$(a$, 1)) + VAL(RIGHT$(b$, 1)) + cry
c$ = c$ + LTRIM$(STR$(c MOD 10))
cry = c \ 10
IF a$ <> "" THEN a$ = LEFT$(a$, LEN(a$) - 1)
IF b$ <> "" THEN b$ = LEFT$(b$, LEN(b$) - 1)
LOOP
IF cry THEN c$ = c$ + "1"
FOR d = LEN(c$) TO 1 STEP -1
d$ = d$ + MID$(c$, d, 1)
NEXT
PRINT "sum = "; d$





 
 Respond to this message