Where is the mistake in this BASIC program?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

chatterjee

Thread Starter
Joined
Jul 12, 2005
Messages
573
I've tried to make a program to find out two midlle terms from a middle term factor.But it's not working as expected.Where is the mistake?Please point out,I'll be debted to you.

Code:
[SIZE="4"]10 cls
20 input "terminal value1";tv1
30 input "terminal value2";tv2
40 input "middle term";mt
45 m=tv1*tv2
50 for a=m to -m step -1
60   for b=m to -m step -1
70 if a+b=mt then goto 90 else goto 100
90 if a*d=m then goto 130
100 next b
110 next a
120 print "It is not a middle term factor":goto 140
130 print a,b
140 end[/SIZE]
 

chatterjee

Thread Starter
Joined
Jul 12, 2005
Messages
573
Oh sorry..I've mistyped it.But I'm sure that it isn't working for any other reasons but this one,because I type it correctly but to no avail.
 

OBP

Joined
Mar 8, 2005
Messages
19,896
What chicon means is that in your listing d has a value of 0, should it have been b that you typed in line 90?
Can you give an example of the value that you entered and the results you get against the results you expected.
You could add a couple of subroutines to just print the results of a+b versus mt and a*b versus m to aid your evaluation.
 

chatterjee

Thread Starter
Joined
Jul 12, 2005
Messages
573
Yes it'll be b.But still I'm having problem.No matter which no.s I feed,it gives me "It is not a middle term factor".

The input was respectively 2,-120 and 14.It's a middle term factor,I think because if it is resolved into factors,it goes (a+12)(2a-10).Hence the result should have been 24,-10.

See the screenshot,please:
 

OBP

Joined
Mar 8, 2005
Messages
19,896
chaterjee, I have found your problem.
The value of m is -240.
In your for/next with a step -1 the first value is -241 which is outside your for next loop.
Try removing the step -1.
 

chatterjee

Thread Starter
Joined
Jul 12, 2005
Messages
573
Oh thanks!It's done!

Actually,yesterday I also found the same mistake and tried to cure it in a different manner.I was sure that there was something wrong with the loop and that was caused by messing up the signs-'+' and '-'.

So,I tried to convert the '-' no.s into '+' ones and to my surprise it was done.

But I never thought that it should have been done simply by removing STEP -1.Thanks again,sir!

I would like to enclose my program which was corrected yesterday.


Code:
[SIZE=4]10 CLS
20 INPUT "terminal value1"; tv1
30 INPUT "terminal value"; tv2
31 IF tv1 OR tv2 < 0 THEN x = tv1 OR tv2 * -1
40 INPUT "middle term"; mt
45 m = tv1 * tv2
50 FOR a = x TO -x STEP -1
60  FOR b = x TO -x STEP -1
70 IF a + b = mt THEN GOTO 90 ELSE GOTO 100
90 IF a * b = m THEN GOTO 120
100 NEXT b
110 NEXT a
120 PRINT a, b: GOTO 140
130 PRINT "It is not a middle term factor"
140 END[/SIZE]
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top