Programming Challenge!
02-19-2017, 10:35 PM (This post was last modified: 02-19-2017 11:00 PM by toml_12953.)
Post: #1
 toml_12953 Senior Member Posts: 2,096 Joined: Dec 2013
Programming Challenge!
My job was to convert old-style BASIC programs to the Prime's HPPL.
Below is an example from Problems for Computer Solution by Stephen J. Rogowski. It is a classic example of spaghetti code that I converted to work on the Prime. Just so you don't think I'm trying to get someone here to do my work for me, I will post another message with my solution. If you want to do the mental exercise, don't look at the solution post before trying the conversion yourself! That would spoil the fun!

Tom L

Code:
10 DIM X(126),K(2) 20 DEF FNA(X,Y,Z)=X*SIN(Y*0.01745329)*Z-16*Z^2 30 PRINT "INPUT MUZZLE VELOCITY (FT/SEC) AND ANGLE (DEGREES)" 40 LET F2=0 50 INPUT M,A 60 LET X(0)=0 70 FOR T=0.2 TO 25 STEP 0.2 80 LET L=INT(5*T+0.001) 90 LET X(L)=FNA(M,A,T) 100 IF X(L)<0 THEN GOTO 150 110 IF X(L)-X(L-1)<=0 AND F2=0 THEN GOTO 250 ELSE GOTO 350 120 LET K(1)=X(L-2) 130 LET W4=T-0.4+J 140 GOTO 280 150 LET W=L-1 160 FOR J=0.01 TO 0.2 STEP 0.01 170 LET K(1)=FNA(M,A,T-0.2+J) 180 IF K(1)<0 THEN GOTO 200 190 NEXT J 200 PRINT "MAXIMUM HEIGHT IS ";K1;" FEET" 210 LET Y=M*COS(A*0.01745329)*(T-0.2+J-0.01) 220 PRINT "RANGE IS ";Y;" FEET" 230 PRINT "TOTAL TIME AIRBORNE IS ";T+J-0.01;" SECONDS" 240 GOTO 360 250 IF X(L-1)-X(L-2)<X(L)-X(L-1) THEN GOTO 120 260 LET K(1)=X(L-1) 270 LET W4=T-0.2+J 280 LET F2=1 290 FOR J=0.01 TO 0.2 STEP 0.01 300 LET K(2)=FNA(M,A,W4) 310 IF K(1)-K(2)<=0 THEN GOTO 340 320 LET K(1)=K(2) 330 NEXT J 340 LET K1=MAX(K(1),K(2)) 350 NEXT T 360 IF K1+10>60 THEN GOTO 470 ELSE LET M1=1 370 FOR D=1 TO 62 380 PRINT TAB(11);"+"; 390 NEXT D 395 PRINT 400 PRINT "0";TAB(11);"+" 410 FOR N=1 TO W 420 PRINT 0.2*N*M*COS(A*0.01745329);TAB(11);"+";TAB(X(N)*M1+11);"*" 430 NEXT N 440 PRINT "ANYMORE (YES OR NO)"; 450 INPUT A$460 IF UCASE$(A\$)="YES" THEN GOTO 30 ELSE GOTO 500 470 LET M1=1/(INT(K1/60+1)) 480 PRINT "SCALE OF HEIGHT IS 1 SPACE = ";1/M1;" FEET" 490 GOTO 370 500 END

Tom L
Cui bono?
 « Next Oldest | Next Newest »

 Messages In This Thread Programming Challenge! - toml_12953 - 02-19-2017 10:35 PM RE: Programming Challenge! A Solution - toml_12953 - 02-19-2017, 10:40 PM RE: Programming Challenge! - Han - 02-20-2017, 04:39 PM RE: Programming Challenge! - toml_12953 - 02-20-2017, 10:52 PM

User(s) browsing this thread: 1 Guest(s)