Hi,
I need to make a program which can handle variable larger than 1,000,000,000 for addition. The problem with integers is that I start getting 1.0E09 which I don't want. I tried to make them string but then I can't do simple addition with numbers like v=v+10 it would say "type mismatch". Any suggestions. Thanks in advance.

Integers are limited to -32768 to 32767 but double precision numbers go much further. You can also use DIM x as DOUBLE at the top of your program as in:

DIM x as DOUBLE
INPUT x
PRINT x + x
END

Double precision will give you up to 15-digits to use for the sum of your numbers. Beyond that, you would need to convert with strings and a function to add together. I know you stated integers, which means you could use long (&) but double allows for larger integers than long does, even though it 'doubles' for decimal numbers.

Personally, I always like to convert to strings for most applications to avoid other problems but if this gets you by for what you need, great. I would like to know what type of project you are working on and if you need some help in the future, just post the code you have so far and ask for help where you are stuck?

Pete

This message has been edited by The-Universe on Jul 5, 2008 9:55 AM

GENERIC GALLEON COMPILER IS NOT READY YET AND I'M NOT SUPPOSED TO MENTION IT IN THIS FORUM AND EVEN THOUGH IT USUALLY GETS BETTER WITH EACH DEMO WHICH IS USUALLY RELEASED EVERY MONTH (A MONTH ON THE THIRD PLANET FROM THE SUN ("EARTH") IS ONE TWELFTH-PART OF THE TIME IT TAKES FOR THE PLANET TO REVOLVE AROUND THE SUN, WHICH IS USUALLY THIRTY TIMES THE TIME IT TAKES FOR THE PLANET TO ROTATE ON ITS AXIS), YOU MIGHT TRY IT AND GIVE UP ON IT AND NEVER USE IT AGAIN. DO NOT EAT QB64.

The E number may be ugly, but it is an actual number. Do your math and then try printing it. PRINT USING to slightly less than the full number places should eliminate the D or E.

Actually if you INPUT a number E is also considered a number and will not create a Redo from start error either.

Thanks for the response on both website. I actually need the last digits so I can't have E at all. Even if there was a way to print as a number (not with E) after all the additions that would have worked too.
Thanks again

adddecstr adds two non-negative integers, in the form of strings. The result is stored in the first string. The strings should contain only ASCII decimal numerals in big-endian order. It should work with input strings up to 32766 bytes long, but I haven't tested it with strings that big.

Regards,
Michael

'public domain, april 2011, michael calkins
DEFINT A-Z
SUB adddecstr (a AS STRING, b AS STRING)
DIM i AS INTEGER
DIM c AS INTEGER
DIM n AS INTEGER
n = LEN(b) - LEN(a)
IF n < 0 THEN n = 0
a = STRING$(n + 1, &H30) + a
c = 0
FOR i = 0 TO LEN(a) - 1
IF i >= LEN(b) THEN
n = &H30
ELSE
n = ASC(MID$(b, LEN(b) - i, 1))
END IF
n = c + ASC(MID$(a, LEN(a) - i, 1)) + n + &HFFD0
IF n > &H39 THEN
c = 1
n = n - &HA
ELSE
c = 0
END IF
MID$(a, LEN(a) - i, 1) = CHR$(n)
NEXT
FOR i = 1 TO LEN(a)
IF ASC(MID$(a, i, 1)) > &H30 THEN a = MID$(a, i): EXIT FOR
IF i = LEN(a) THEN a = CHR$(&H30)
NEXT i
END SUB

This function is similar to the other one in a few ways, but also different in a few ways.

Like the other one, it accepts two input strings of basically any lengths. Like the other one, it stores the result in the first string.

In this case, the string is not a sequence of decimal numerals in big-endian order, but is a little-endian unsigned integer of arbitrary size.

Note that in this function, as well as in the last, the two input strings can be different lengths. The first one, since it will store the result, is expanded to the size of the larger string, plus 1, to accommodate a possible carry. Afterward, leading zeros are removed. In the case of the other function, 0 becomes "0". In the case of this function, 0 becomes "", an empty string.

Regards,
Michael

'public domain, april 2011, michael calkins
DEFINT A-Z
SUB addbinstr (a AS STRING, b AS STRING)
DIM i AS INTEGER
DIM c AS INTEGER
DIM n AS INTEGER
n = LEN(b) - LEN(a)
IF n < 0 THEN n = 0
a = a + STRING$(n + 1, &H0)
c = 0
FOR i = 1 TO LEN(a)
IF i > LEN(b) THEN
n = &H0
ELSE
n = ASC(MID$(b, i, 1))
END IF
n = c + ASC(MID$(a, i, 1)) + n
IF n AND &H100 THEN
c = 1
n = n AND &HFF
ELSE
c = 0
END IF
MID$(a, i, 1) = CHR$(n)
NEXT
FOR i = LEN(a) TO 1 STEP -1
IF ASC(MID$(a, i, 1)) > &H0 THEN a = LEFT$(a, i): EXIT FOR
IF i = 1 THEN a = ""
NEXT i
END SUB

This message has been edited by MCalkins on Apr 26, 2011 10:17 PM This message has been edited by MCalkins on Apr 26, 2011 10:16 PM

Say 1st 8 digits, 2nd 8 digits etc. then do the adds with carries.

That's how the processor does it. Remember qbasic is only 16 bit. So for long integers when the 16 bit overflows it starts again and the carry bit is set to one.