符号没有隐式类型

时间:2015-09-15 13:01:42

标签: fortran

我通过fortran 90运行此代码

   Program Projectile
! This Program Calculates the Velocity and Height of a
! Projectile
! Given its Initial Height, Initial Velocity and Constant
! Acceleration.
Implicit None
Real :: Initial_Hight, Height, Initial_Velocity, Velocity, &
Time, Acceleration = -9.807
! Obtain Values for Initial Height, Initial Velocity and
! Time
Print*, "Enter the Initial Height and Velocity:"
Read*, Initial_Height, Initial_Velocity
Print*, "Enter Time at Which to Calculate Height and &
Velocity:"
Read*, Time
! Calculate the Height and Velocity
Height = 0.5 * Acceleration * Time ** 2 + Initial_Velocity &
* Time + Initial_Height
Velocity = Acceleration * Time + Initial_Velocity
! Display Velocity and Height
Print*, "At Time", Time, "The Vertical Velocity is", Velocity
Print*, "and the Height is", Height
End Program Projectile

但我不断得到这个错误:错误符号'initial_height'没有IMPLICIT类型,并且在删除隐含的无行之后我不能使用实数,因为实数会导致另一个错误,你可以帮助我吗?

2 个答案:

答案 0 :(得分:2)

你的代码中只有一个拼写错误:

Real :: Initial_Hight, Height, Initial_Velocity, Velocity, &
  Time, Acceleration = -9.807

应该阅读

Real :: Initial_Height, Height, Initial_Velocity, Velocity, &
  Time, Acceleration = -9.807

答案 1 :(得分:1)

你有两个问题。

正如吉尔斯所指出的,你现有的代码中有一个拼写错误。

您的第二个问题是您不了解FORTRAN隐式类型规则。名称以I,J,K,L,M或N开头的变量是隐式INTEGER,除非另有声明。除非另有声明,否则所有其他变量都是隐式REAL。

INITIAL_HEIGHT隐式为INTEGER,除非你声明它是REAL,你没有这样做。你声明INITIAL_HIGHT是真的,你没有声明INITIAL_HEIGHT。通常,它会隐式地成为INTEGER,它会导致真正的barf赋值。因为你完全禁用了隐式输入,所以通过IMPLICIT NONE,INITIAL_HEIGHT没有类型。

这就是编译器试图告诉你的。