Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Division by zero

Status
Not open for further replies.

qbasicking

Programmer
Aug 19, 2001
628
US
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?

If a man says something in the forest and no woman hears it is he still wrong?
 
Hey. I need to know what "bt" and "ct" are. I can't figure it out without the values. Obviously the program is trying to divide something by zero, but without the other values I can't find the error.

Doug :)
 
Maybe I'm presumptious but "bt/tangent/ct" are ARRAYS. But, I too need the numbers as well.

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
 
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)

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?
 
put it together as
Code:
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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top