Fortran: determine the horizontal distance of a ball

In summary: END In summary, the program is trying to set values for an array, but it's not clear what the code is supposed to be doing. The code has an infinite loop, and the distance is not being computed correctly.
  • #1
CCguru
2
0
Im writing a program to determine the horizontal distance of a ball but getting this error:

Y(t)=Y0+VY0*t+(1/2)*g*t^2
1
Error: Unclassifiable statement at (1)

Distance=(X(t))^2+(Y(t))^2
1
Error: Unclassifiable error at (1)



My code is as follows:

PROGRAM as_the_ball_is_thrown

IMPLICIT NONE

INTEGER::Y0, X0, V0, g, theta, t
CHARACTER::Distance, VY0, VX0, X(t), Y(t)


X0=0
Y0=0
V0=20
g=9.81


WRITE(*,*) "Please enter amount of time the ball traveled"
READ(*,*) t

WRITE(*,*) "Please enter the angle to which the ball was thrown"
READ(*,*) theta

DO
Y(t)=Y0+VY0*t+(1/2)*g*t^2
X(t)=X0+VX0*t
VX0=V0*COS(theta*3.14159/180)
VY0=V0*SIN(theta*3.14159/180)
Distance=(X(t))^2+(Y(t))^2
END DO


WRITE(*,*) "The horizontal distance the ball traveled is"
READ(*,*) Distance
WRITE(*,*) "meters"

END PROGRAM as_the_ball_is_thrown



Can anyone tell me why this is wrong?

Thanks!
 
Technology news on Phys.org
  • #2


^ is not the Fortran operator for "raise to a power". It should be **.

Also (1/2) will be evaluated in integer arithmetic since 1 and 2 are both integers, and the integer division will give 0 which is not what you want. The best fix is to replace (1/2) by 0.5.

Declaring Y0, X0, V0, g, theta, t as INTEGER is probably not a good idea, especially since you then try to set g = 9.81 (which will actually set it to 9).
 
  • #3


In addition to what AlephZero said, you have problems with your declarations for X(t) and Y(t). For one thing, this is not how you declare arrays. For another thing, why are these character-type variables? That doesn't make any sense.
 
  • #4


Awesome thanks! That fixed all the errors. Now for some reason the program just stops and doesn't print anything after a person enters the angle. Do you guys know why?
 
  • #5


There are a couple things wrong.
1) You have what I believe is an infinite loop below where you shouldn't be using a loop at all. OTOH, if you are trying to set the values of an array to certain values, maybe that's what you're trying to do. If that's the case, the following code won't work, because array indexes have to be integer values 1, 2, 3, and so on.

It's hard to tell what you're trying to do, though.
Code:
DO
 Y(t)=Y0+VY0*t+(1/2)*g*t^2
 X(t)=X0+VX0*t
 VX0=V0*COS(theta*3.14159/180)
 VY0=V0*SIN(theta*3.14159/180)
 Distance=(X(t))^2+(Y(t))^2 
END DO

2. Distance is computed, so you don't need to READ it, just WRITE it.
Code:
WRITE(*,*) "The horizontal distance the ball traveled is"
 READ(*,*) Distance 
WRITE(*,*) "meters"
 

1. What is Fortran?

Fortran is a high-level programming language commonly used for scientific and engineering applications. It stands for Formula Translation and was originally developed in the 1950s.

2. How can I determine the horizontal distance of a ball using Fortran?

To determine the horizontal distance of a ball using Fortran, you will need to use the formula for projectile motion, which takes into account the initial velocity, angle of launch, and time. You can input these values into your Fortran program and use the appropriate mathematical functions to calculate the horizontal distance.

3. Is Fortran the best language to use for this task?

Fortran is a popular language for scientific and engineering calculations, so it may be a good choice for determining the horizontal distance of a ball. However, there may be other programming languages that could also be used for this task, depending on your specific needs and preferences.

4. Can I use Fortran for other scientific calculations?

Yes, Fortran is commonly used for a variety of scientific and engineering calculations, including those related to physics, chemistry, and geology. It has built-in functions for mathematical operations and can handle large amounts of data efficiently.

5. Do I need any special programs or tools to use Fortran for this task?

In order to write and run a Fortran program for determining the horizontal distance of a ball, you will need a Fortran compiler. These are available for free online and can be downloaded onto your computer. You may also want to use a text editor or integrated development environment (IDE) to write your code and run it within the compiler.

Similar threads

  • Programming and Computer Science
Replies
4
Views
615
  • Programming and Computer Science
Replies
8
Views
1K
  • Introductory Physics Homework Help
Replies
4
Views
530
  • Programming and Computer Science
Replies
2
Views
16K
  • Programming and Computer Science
Replies
8
Views
1K
  • Introductory Physics Homework Help
Replies
10
Views
1K
  • Introductory Physics Homework Help
Replies
6
Views
2K
  • Programming and Computer Science
Replies
12
Views
963
  • Programming and Computer Science
Replies
8
Views
2K
  • Introductory Physics Homework Help
2
Replies
38
Views
1K
Back
Top