我正在通过 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
Run Code Online (Sandbox Code Playgroud)
但我经常收到这个错误:错误符号“initial_height”没有 IMPLICIT 类型,擦除隐式 none 行后我不能使用实数,因为实数会导致另一个错误,你能帮我吗?
你有两个问题。
正如吉尔斯指出的那样,您现有的代码中有一个错字。
您的第二个问题是您不了解 FORTRAN 隐式类型规则。除非另有声明,否则名称以 I、J、K、L、M 或 N 开头的变量是隐式整数。除非另有声明,否则所有其他变量都是隐式 REAL。
INITIAL_HEIGHT 是隐式整数,除非您声明它为 REAL,而您并没有这样做。您将 INITIAL_HIGHT 声明为 REAL,而未声明 INITIAL_HEIGHT。通常,它会被隐式设置为 INTEGER,这会导致对 barf 进行真正的赋值。因为您完全禁用了隐式类型,通过 IMPLICIT NONE,INITIAL_HEIGHT 没有类型。
这就是编译器试图告诉你的。
| 归档时间: |
|
| 查看次数: |
29243 次 |
| 最近记录: |