Hello, i want to write a program to print out a table showing time in 0.1 sec, soldier’s position, arrow’s position, and the distance in feet between the arrow and the soldier every tenth of a second until the arrow hits the soldier or he escapes, if he was X feet away from the barbarian when the arrow was loosed. Assume that the arrow travels at a constant velocity of 72 mph and the roman soldier runs at a constant speed of 12 mph. The range of the arrow is 120 feet. Print out how many seconds it took for the arrow to hit the
soldier or for the soldier to escape. The only input that is required is the distance of the soldier from the barbarian when the barbarian took the shot.

Dani AI

Generated

A compact clarification, numeric check, and a ready-to-run Python example to complement the replies from and . Assumptions are made explicit: the arrow is fired from x = 0 toward a soldier initially at x = X (feet) and the soldier runs directly away along that line at constant speed. No projectile arc or drag is modeled (see and if a full ballistic model is desired).

Key facts and checks:

  • 72 mph = 105.6 ft/s; 12 mph = 17.6 ft/s. Arrow range = 120 ft so t_range = 120 / 105.6 ≈ 1.13636 s.
  • Continuous catch time (if arrow is faster) is t_hit = X / (va - vs).
  • Distance as a function of time: d(t) = X + vst - min(vat, 120).
  • Immediate escape if X > 120 (soldier starts outside range). If va <= vs the arrow never catches up.

Algorithm summary:

  1. Convert units. 2) If X > 120 -> escaped at t=0. 3) If va <= vs -> escaped. 4) Compute t_hit and compare with t_range. 5) Print rows at t = 0.0, 0.1, 0.2, ... up to the last full 0.1 step before the event, then print a final row at the exact event time (t_hit or t_range). This avoids missing a hit that occurs between 0.1-s steps.

Example Python (prints time, soldier pos, arrow pos, distance):

# Linear chase simulation: arrow at x=0, soldier at x=X (ft)
va = 72.0 * 5280.0 / 3600.0   # arrow ft/s (105.6)
vs = 12.0 * 5280.0 / 3600.0   # soldier ft/s (17.6)
rng = 120.0
dt = 0.1

X = float(input("Initial distance (ft): "))

if X > rng:
    print("Soldier out of range at t=0. Escaped.")
else:
    if va <= vs:
        print("Arrow cannot catch soldier; escaped.")
    else:
        t_hit = X / (va - vs)
        t_range = rng / va
        t_end = min(t_hit, t_range)
        print("{:>6} {:>12} {:>12} {:>12}".format("t(s)", "soldier(ft)", "arrow(ft)", "distance(ft)"))
        t = 0.0
        while t + 1e-9 < t_end:
            arrow_x = min(va * t, rng)
            soldier_x = X + vs * t
            dist = soldier_x - arrow_x
            print("{:6.1f} {:12.3f} {:12.3f} {:12.3f}".format(t, soldier_x, arrow_x, dist))
            t += dt
        arrow_x = min(va * t_end, rng)
        soldier_x = X + vs * t_end
        dist = soldier_x - arrow_x
        print("{:6.3f} {:12.3f} {:12.3f} {:12.3f}".format(t_end, soldier_x, arrow_x, dist))
        if t_hit <= t_range:
            print("Hit at {:.3f} s".format(t_hit))
        else:
            print("Escaped; arrow reached max range at {:.3f} s".format(t_range))

Notes: use the exact t_hit for the final row rather than relying solely on 0.1-s steps to avoid rounding misses. Translating to C is straightforward (same formulas, loop and printf).

Recommended Answers

All 5 Replies

Well, what's stopping you?
You want to write it, so I guess you're not asking us to do it for you?

Hello, i want to write a program to print out a table showing time in 0.1 sec, soldier’s position, arrow’s position, and the distance in feet between the arrow and the soldier every tenth of a second until the arrow hits the soldier or he escapes, if he was X feet away from the barbarian when the arrow was loosed. Assume that the arrow travels at a constant velocity of 72 mph and the roman soldier runs at a constant speed of 12 mph. The range of the arrow is 120 feet. Print out how many seconds it took for the arrow to hit the
soldier or for the soldier to escape. The only input that is required is the distance of the soldier from the barbarian when the barbarian took the shot.

As the rule of the Forum first you have to do something instead asking someone for doing it .
You have to show what have you done and what's the problem I see here like u wanna ready programm not help...


Submit your code and then people will help to find your problem...
:D

I would suggest looking at Projectile physics if you wanted to code that! post back any attempts though! :)

It seems i m back in +2 and studying mechanics....newtons law ...ha ha

Google for Ballistics Game Programming.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.