Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with a program
#1
Well, im new to QBASIC... And I was hoping you guys could help me out... What i want to do is divide the larger of the numbers by the smaller... But someone might put in zero.... So I need to figure out why it keeps saying that all numbers = zero, when they dont. Please Please help me out on this guys!! Every thing works fine eccept the zero part....


Thanks!! Ref

Code:
REM woooOOoooo
CLS
PRINT "After the ? Appears please enter two number separated by a comma and hit enter. The Larger number will be divided by the smaller number"
PRINT TAB(2) "A" TAB(15) "B" TAB (30) "A/B" TAB(45) "B/A"
PRINT TAB(0) "---" TAB(14) "---" TAB(29) "-----" TAB(44) "-----"

40 FOR j = 1 TO 13
    INPUT a, b
    [b]IF a OR b = 0 THEN 30[/b]
    IF a > b THEN 10
    IF a < b THEN 20
NEXT J

10 c = a / b
PRINT TAB(2) a TAB(15) b TAB(30) c
IF a > b THEN 40

20 d = b / a
PRINT TAB(2) a TAB(15) b TAB(30) d
IF a < b THEN 40

30 PRINT TAB(2) a TAB(15) b TAB(30) "Division by zero not defined
IF a OR b = 0 THEN 4


I just realised I can put
Code:
IF a = 0 THEN 30
IF b = 0 THEN 30
But i would like to use the "OR" why wont it work with the or?
Reply
#2
Code:
IF a OR b = 0 THEN 4
should be
Code:
IF a OR b = 0 THEN 40


i think that's that problem
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
Uhh, it says "IF a OR b = 0 THEN 30" xD
Reply
#4
The line whitetiger is equal to
Code:
IF a <> 0 OR b = 0 THEN

It should be
Code:
IF a = 0 OR b = 0 THEN

If you want to check if a = 0 or b =0

also in general:
put an "END" right after the FOR/NEXT loop
because then and then you could replace all the
IF ... THEN 40
with GOTO 40

Edit: YAY [rainbow]999[/rainbow] posts WOW! who would've believed that!?
/post]
Reply
#5
OR doesn't work the way you are trying to use it here.

if you want to check to see if either of the numbers is zero, do this:

Code:
IF a% = 0 OR b% = 0 THEN GOTO 40

*peace*

Meg.

edit: heh, two people responded while I was typing!

edit: I put % after the numbers. those wouldn't be used in your code.
Reply
#6
Code:
If a+b = 0 Then
Code:
If ABS(a+b) = 0 Then
Code:
If ABS(a)+ABS(b) = 0 Then

Not that it matters or anything Tongue
Reply
#7
woah I cant believe I didn't notice that!

sheesh =/ Im going blind!
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#8
Thanks guys!! Ill go try now. Big Grin!!

BTW: Congrats on 999 posts Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)