Fortran77固定格式.f文件编译错误修复问询(无需额外编译选项)
报错原因
你的代码混用了Fortran90+的语法,且不符合.f后缀默认使用的Fortran77固定格式规范,具体问题如下:
- Fortran77固定格式要求可执行代码、声明代码必须从第7列开始编写,你代码中的
implicit none、变量声明等行顶格编写,不符合格式要求 - 变量声明用的
::是Fortran90引入的语法,纯Fortran77不支持该写法 - 变量
choice未初始化就用在do while的判断条件中,运行时会出现随机行为 - 存在拼写笔误(退出提示里的
progrm应为program)
修复后可正常编译运行的代码
program p1 implicit none integer choice real inputValue C 初始化choice为非0值,保证首次正常进入循环 choice = 1 do while(choice /= 0) print *, ' ' print *, 'Enter a conversion option (1-6 or 0 to exit):' print *, '-------------' print *, '(1) Pounds to Kilograms' print *, '(2) Kilograms to Pounds' print *, '(3) Feet to meters' print *, '(4) Meters to feet' print *, '(5) farenheit to Celsius' print *, '(6) Celsius to Fahrenheit' print *, '(0) Exit this program' print *, '-------------' READ(*,*) choice IF (choice == 1) THEN print *, 'Please enter the number of Pounds to be converted into Kilograms' READ(*,*) inputValue inputValue = inputValue / 2.20 print *, 'Your value is:', inputValue ELSE IF (choice == 2) THEN print *, 'Please enter the number of Kilograms to be converted into Pounds' READ(*,*) inputValue inputValue = inputValue * 2.20 print *, 'Your value is:', inputValue ELSE IF (choice == 3) THEN print *, 'Please enter the number of Feet to be converted into Meters' READ(*,*) inputValue inputValue = inputValue / 3.28 print *, 'Your value is:', inputValue ELSE IF (choice == 4) THEN print *, 'Please enter the number of Meters to be converted into Feet' READ(*,*) inputValue inputValue = inputValue * 3.28 print *, 'Your value is:', inputValue ELSE IF (choice == 5) THEN print *, 'Please enter the number of Fahrenheit to be converted into Celsius' READ(*,*) inputValue inputValue = (5.0/9.0) * (inputValue - 32) print *, 'Your value is:', inputValue ELSE IF (choice == 6) THEN print *, 'Please enter the number of Celsius to be converted into Fahrenheit' READ(*,*) inputValue inputValue = (inputValue * 9.0/5.0) + 32 print *, 'Your value is:', inputValue ELSE IF (choice == 0) THEN print *, 'EXIT' END IF ENDDO end
内容的提问来源于stack exchange,提问作者user12577766
相关产品推荐
相关产品推荐

