IF instruction doesn't work?
-
- Newbie
- Posts: 3
- Joined: Sat Dec 15, 2007 7:23 am
IF instruction doesn't work?
I have this piece of code. When I input equal values for CLO(I) and CL(I)
the program recognizes them as CLO(I) > CL(I). I tried many other options and they didn't work. I removed the line 1280 and the application doesn't make the calculations. Any help? What I am doing wrong?
This an adapted code from GWBASIC.
Thanks a lot
1260 FOR I = 1 TO NTR
1270 PRINT "Tube "; I; ": Q(l/s),L(m),h(M) "; : INPUT Q2(I), CL(I), CLO(I)
1280 IF (CLO(I) > CL(I)) THEN
1282 GOTO 1270
1284 END IF
1290 NEXT I
1340 PRINT "I am calculating. Wait a moment please"
1350 ....( calculating)
the program recognizes them as CLO(I) > CL(I). I tried many other options and they didn't work. I removed the line 1280 and the application doesn't make the calculations. Any help? What I am doing wrong?
This an adapted code from GWBASIC.
Thanks a lot
1260 FOR I = 1 TO NTR
1270 PRINT "Tube "; I; ": Q(l/s),L(m),h(M) "; : INPUT Q2(I), CL(I), CLO(I)
1280 IF (CLO(I) > CL(I)) THEN
1282 GOTO 1270
1284 END IF
1290 NEXT I
1340 PRINT "I am calculating. Wait a moment please"
1350 ....( calculating)
Debugging Suggestion
Insert line after 1270 and run again. Report what you see.
Mac
Mac
Code: Select all
1260 FOR I = 1 TO NTR
1270 PRINT "Tube "; I; ": Q(l/s),L(m),h(M) "; : INPUT Q2(I), CL(I), CLO(I)
print "Debug: ";CL(I),CLO(I)
1280 IF (CLO(I) > CL(I)) THEN
Get rid of the line numbers, first of all. You can use them if you want them as labels but otherwise, dump them. Block IFs aren't really designed to work with line numbers. Secondly, and this is more of a coding style thing than anything else, but if you only have one statement in an IF block to process, skip the whole block altogether and just write it all on one line:
Code: Select all
IF (CLO(I) > CL(I)) THEN GOTO 1270
Eliminating the line numbers will not help solve this problem.Nodtveidt wrote:Get rid of the line numbers
Running the program below, I got these results:
1 : Q(l/s),L(m),h(M) ? 1, 5.6, 5.5
2 : Q(l/s),L(m),h(M) ? 1, 5.6, 5.6
3 : Q(l/s),L(m),h(M) ? 1, 5.6, 5.7
3 : Q(l/s),L(m),h(M) ? 1, 1.0, 1.0
I am calculating. Wait a moment please
Note that iteration 3 correctly found the condition to repeat the question.
However; by making the simple change of adding DEFINT A-Z at the top of the program, I got these results:
1 : Q(l/s),L(m),h(M) ? 1, 5.6, 5.5
2 : Q(l/s),L(m),h(M) ? 1, 5.6, 5.6
3 : Q(l/s),L(m),h(M) ? 1, 5.6, 5.7
I am calculating. Wait a moment please
Note that iteration 3 failed to find the condition.
My guess is that the OP is entering fraction input for a whole number variable. Not sure, that's why I ask that the printout be inserted so we could see what is actually being compared, as opposed to what was entered.
Mac
Code: Select all
CLS
NTR = 3
DIM Q2(NTR)
DIM CL(NTR)
DIM CLO(NTR)
1260 FOR I = 1 TO NTR
1270 PRINT I; ": Q(l/s),L(m),h(M) "; : INPUT Q2(I), CL(I), CLO(I)
1280 IF (CLO(I) > CL(I)) THEN
1282 GOTO 1270
1284 END IF
1290 NEXT I
1340 PRINT "I am calculating. Wait a moment please"
Yep. If the OP is interested, here is a program that will remove all line numbers except lables, which it converts say 1020 to L1020.Nodtveidt wrote:Mac wrote:It will help make the code look a hell of a lot cleaner, easier to debug, and not so 1975. :P
http://www.network54.com/Forum/178387/m ... 1197752905
Mac
P.S. Utility is only useful on programs that already run properly on QBasic. It can't fix anything but the line numbers. If the program has PEEK/POKE to VIC-20 system places, etc. they will still be wrong.
Re: IF instruction doesn't work?
If you remove 1280 then you have to also remove 1282 and 1284.Jota de Sousa wrote:I removed the line 1280 and the application doesn't make the calculations
Are you trying to run that program in GWBASIC? If so, you cannot terminate a statement with THEN. You have to code like Nodtveidt
said: Get rid of 1282 and 1284 and put the GOTO on 1280.
If you are trying to run that program in QBasic, it should run fine. I see no problem. So that's why I suggest to put the extra PRINT into the code to see what is going on.
Mac
-
- Newbie
- Posts: 3
- Joined: Sat Dec 15, 2007 7:23 am
The bloody IF statment
Hi Everybody!
Sorry to bother you again.
I have tried everything possible. The program works fine with GWBASIC and worked also with QBASIC since two weeks ago. The instruction IF with the same value on CLO(I) and CL(I) recognizes, in fact, that CLO(I) is greater than CL(I). This is not possible for my calculation.
Here is the inicial code:
1 CLS
10 WIDTH LPRINT 255
50 DEFINT I-N ' I cannot put DEFINT A-Z. It gives other errors.
60 OPTION BASE 1 ' What is this?
80 N = 100: NM = N + 1
90 D1$ = MID$(DATE$, 7, 4)
100 D2$ = MID$(DATE$, 6, 1)
110 D3$ = MID$(DATE$, 1, 3)
120 D4$ = MID$(DATE$, 4, 2)
130 DAT$ = D1$ + D2$ + D3$ + D4$
140 PI = 3.1415926#
150 DIM Q(N), Q1(N), Q2(N), Q9(N), D(N), V(N), CJ(N), CL(N), D0(N), CLO(N) AS DOUBLE
160 DIM N0(NM), N9(NM), H(N), H1(N), H2(N), CL1(N) AS DOUBLE
Thank you all of you if you can find a solution. The strange is that this worked perfectly and suddenly stopped working. I used it with GWBASIC like suggested by Mac and it works fine.
I am using XP Service pack 2 with all the updates.
Thanks anyway.
Sorry to bother you again.
I have tried everything possible. The program works fine with GWBASIC and worked also with QBASIC since two weeks ago. The instruction IF with the same value on CLO(I) and CL(I) recognizes, in fact, that CLO(I) is greater than CL(I). This is not possible for my calculation.
Here is the inicial code:
1 CLS
10 WIDTH LPRINT 255
50 DEFINT I-N ' I cannot put DEFINT A-Z. It gives other errors.
60 OPTION BASE 1 ' What is this?
80 N = 100: NM = N + 1
90 D1$ = MID$(DATE$, 7, 4)
100 D2$ = MID$(DATE$, 6, 1)
110 D3$ = MID$(DATE$, 1, 3)
120 D4$ = MID$(DATE$, 4, 2)
130 DAT$ = D1$ + D2$ + D3$ + D4$
140 PI = 3.1415926#
150 DIM Q(N), Q1(N), Q2(N), Q9(N), D(N), V(N), CJ(N), CL(N), D0(N), CLO(N) AS DOUBLE
160 DIM N0(NM), N9(NM), H(N), H1(N), H2(N), CL1(N) AS DOUBLE
Thank you all of you if you can find a solution. The strange is that this worked perfectly and suddenly stopped working. I used it with GWBASIC like suggested by Mac and it works fine.
I am using XP Service pack 2 with all the updates.
Thanks anyway.
extra print
Did you put in the extra PRINT I suggested?
If so, please post the results of your run
By the way
150 DIM Q(N), Q1(N), Q2(N), Q9(N), D(N), V(N), CJ(N), CL(N), D0(N), CLO(N) AS DOUBLE
will only dimension CLO(N) AS DOUBLE
The rest get the default SINGLE.
If you really need DOUBLE, you need separate DIM statements.
Mac
If so, please post the results of your run
By the way
150 DIM Q(N), Q1(N), Q2(N), Q9(N), D(N), V(N), CJ(N), CL(N), D0(N), CLO(N) AS DOUBLE
will only dimension CLO(N) AS DOUBLE
The rest get the default SINGLE.
If you really need DOUBLE, you need separate DIM statements.
Mac
-
- Newbie
- Posts: 3
- Joined: Sat Dec 15, 2007 7:23 am
The IF Statement
Thanks to Mac. In fact, I had never noticed this error because I have
never entered decimal values, only integers. Although the printing
sugested by Mac gave 2.8, 2,8 they were not equal. One of them was a
SINGLE variable and the other a DOUBLE one.
This is now working fine. There are many errors ( by ignorance ) and
mistakes ( by distraction ) I will try to fix. This is an old, old code written
by a student, ages ago.
Thanks Mac.
never entered decimal values, only integers. Although the printing
sugested by Mac gave 2.8, 2,8 they were not equal. One of them was a
SINGLE variable and the other a DOUBLE one.
This is now working fine. There are many errors ( by ignorance ) and
mistakes ( by distraction ) I will try to fix. This is an old, old code written
by a student, ages ago.
Thanks Mac.