Post Reply 
Programming Challenge!
02-20-2017, 10:52 PM (This post was last modified: 02-20-2017 10:55 PM by toml_12953.)
Post: #4
RE: Programming Challenge!
(02-20-2017 04:39 PM)Han Wrote:  After a quick glance at the BASIC code, I wondered if you may be better off looping on L from 1 to 125 (or 126?) and then calculating T to be T:=T+0.2; or T:=L/5. This avoids having to round off with IP().

That's true but since I was trying to stay as close as possible to the original, I opted to keep the same looping. I also wrote a much better version that uses an algebraic technique rather than this iterative solution. It's much shorter and more accurate but I didn't use it for the same reason as above.

Code:
FNH(V,T)
BEGIN
  RETURN -16*T^2+V*T;
END;

EXPORT PROJECTILE()
BEGIN
  PRINT();
  LOCAL VERT,HORIZ,T2,MAXHT,SCALE,AIRTIME,RANGE,HEIGHT;
  LOCAL DIST,V0,HEIGHT,OMODE;
  OMODE:=HAngle; //Save current angle mode
  HAngle:=1; // Set degree mode
  INPUT({V0,A},"MUZZLE VELOCITY AND ANGLE",{"V FT/SEC: ","A DEGREES: "});
  VERT:=V0*SIN(A);
  HORIZ:=V0*COS(A);
  T2:=VERT/32.1740485564;
  MAXHT:=FNH(VERT,T2);
  SCALE:=IP(MAXHT/60+1);
  AIRTIME:=T2*2;
  RANGE:=HORIZ*AIRTIME;
  PRINT("MAXIMUM HEIGHT IS "+MAXHT);
  PRINT("RANGE IS "+RANGE);
  PRINT("TOTAL TIME AIRBORNE IS "+AIRTIME+" SECONDS");
  PRINT("SCALE OF HEIGHT IS 1 SPACE = "+SCALE+" FEET");
  PRINT(TAB(14)+"++++++++++++++++++++++++++++++");
  PRINT(TAB(9)+"0   +");
  T:=0.2;
  REPEAT
    HEIGHT:=FNH(VERT,T);
    DIST:=HORIZ*T;
    PRINT(ROUND(DIST,4)+" +"+TAB(HEIGHT/SCALE)+"*");
    T:=T+AIRTIME/26;
  UNTIL FNH(VERT,T)<0;

  HAngle:=OMODE; // Reset original angle mode

END;

Tom L

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Programming Challenge! - toml_12953 - 02-19-2017, 10:35 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)