Division by zero
Division by zero
(OP)
I keep getting a 'division by zero error' in this code:
FOR a% = 0 to 1800
IF bt(a%) = 0 THEN bt(a%) = .01
tangent(a%) = ct(a%) / bt(a%)
NEXT
I don't understand how that is possible, could somebody help me out?
FOR a% = 0 to 1800
IF bt(a%) = 0 THEN bt(a%) = .01
tangent(a%) = ct(a%) / bt(a%)
NEXT
I don't understand how that is possible, could somebody help me out?
If a man says something in the forest and no woman hears it is he still wrong?
RE: Division by zero
Doug
RE: Division by zero
All I keep getting is "subscript out of range" and it stops at A% = 11.
So, I changed the % [which is for INTEGER data types] to a "low floating point" variable by using the ! [which is for SINGLE data types] because you are using a fraction (".01") in your IF clause.
Also, the FOR/NEXT will NOT BREAK OUT until it reaches 1 number higher than the number it was told to count upto (see note after test code)
'--------start test
CLS
DIM Bt!(1801), Ct!(1801), Tangent!(1801)
FOR a! = 0 TO 1800
IF Bt(a!) = 0 THEN Bt(a!) = .01
Tangent(a!) = Ct(a!) / Bt(a!)
NEXT
PRINT "The total counted: ";
PRINT a!
'--------end test
if you run the above the a! should show you 1801--double check your arrays, are they high enough? redimmed higher?.
--MiggyD
RE: Division by zero
bt(t%) = COS(t% * ATN(1) / 225)
ct(t%) = SIN(t% * ATN(1) / 225)
NEXT t%
st(0) = 10 ^ -9
st(900) = st(0)
st(1800) = st(0)
ct(450) = st(0)
ct(1350) = st(0)
The values for ct() and bt() have been BSAVEd, so I couldn't get them directly. I am pretty sure that these are the equations I used to get them.
If a man says something in the forest and no woman hears it is he still wrong?
RE: Division by zero
DIM bt(1800), ct(1800), tangent(1800), st(1800)
FOR t% = 0 TO 1800
bt(t%) = COS(t% * ATN(1) / 225)
ct(t%) = SIN(t% * ATN(1) / 225)
NEXT t%
st(0) = 10 ^ -9
st(900) = st(0)
st(1800) = st(0)
ct(450) = st(0)
ct(1350) = st(0)
FOR a% = 0 TO 1800
IF bt(a%) = 0 THEN bt(a%) = .01
tangent(a%) = ct(a%) / bt(a%)
NEXT
- it doesn't say any error in QB 1.1!
RE: Division by zero
Antoni
http://www.geocities.com/antonigual/index.html