# Very clever, qbguy, but there are some problems.

S

The program using MOD 9 overflows if the number is too large, whereas it will work with any size string in my code. Also, if the result is 9, it outputs 0.

I amended my program to take those problems into consideration. Here is the revised code, comparing results using both techniques:

=============================================================================
CLS
DIM snum AS STRING, ln AS INTEGER, x AS INTEGER
DIM totnum AS INTEGER, mynum AS INTEGER
DIM snum2 AS STRING, mynum2 AS DOUBLE

INPUT "Enter your number:  ", snum\$
IF VAL(snum\$) <> 0 THEN
snum2\$ = snum\$
ln = LEN(snum\$)
DO
totnum = 0
REDIM numary(ln) AS STRING
FOR x = 1 TO ln
numary\$(x) = MID\$(snum\$, x, 1)
mynum = VAL(numary\$(x))
totnum = totnum + mynum
NEXT x
PRINT "The total of ";
FOR x = 1 TO ln
PRINT numary\$(x);
IF x
PRINT " and ";
ELSE
PRINT " is: ";
END IF
NEXT x
PRINT totnum
snum\$ = MID\$(STR\$(totnum), 2) 'positive numbers start with a space
ln = LEN(snum\$)
LOOP UNTIL ln = 1

PRINT : PRINT
mynum2 = VAL(snum2\$)
ON ERROR GOTO overflo
mynum2 = mynum2 MOD 9
IF mynum2 = 0 THEN mynum2 = 9
PRINT "The total using MOD 9 is "; mynum2
ELSE
PRINT : PRINT "Incorrect entry"
END IF
END

overflo:
PRINT "Number is too big to process with MOD 9."
END
RESUME

 This message has been edited by Solitaire1 on Apr 3, 2011 8:40 AMThis message has been edited by Solitaire1 on Apr 3, 2011 8:39 AM

Posted on Apr 3, 2011, 8:37 AM

 Response Title Author and Date Number 9 Game Modification Error Kevin C on Apr 4 It's a problem with the Network54 Forum display!!!! Solitaire on Apr 4 Are you unchecking the "enable formatted text" checkbox? Michael Calkins on Apr 4 * I believe I did. Solitaire on Apr 4 I've been stung by that too. Pete on Apr 5 Posting > and < when formatting is enabled ChronoKitsune on Apr 4 * if x < ln then Michael Calkins on Apr 6