0

我在编译我编写的这个程序时遇到了麻烦。我花了几个小时试图找出问题所在,但它只是说有两个主要程序根本没有任何帮助。如果有任何帮助,我将不胜感激。谢谢

c   comments
*

    program cylinder

    real diam(10),height(10),volume(10)
    external circ,surface,vol
    integer count,i,j
    parameter (pi = 3.14159)
    j = 0
    count = 1

    do i=1,10
    diam(i) = 0
    end do  

 10 j = j+1
    write(*,*) 'Please enter the diameter and height of
     A  a cylinder'
    read*, diam(j),height(j)

    if (diam(j) .NE. 0 .AND. j .LE. 10) goto 10


 20 write(*,*) 'Cylinder', count, 'Circumfrence =', circ(diam)

    write(*,*) 'Total Surface Area=', 
     B  surface(diam,height)

    Call vol(diam,height,volume)
    write(*,*) 'Volume=', volume(count)

    count = count+1

    if (diam(count) .NE. 0 .AND. count .LE. 10) goto 20

    end

    function circ(d) = d*pi

    function surface(d,h)
    real d,h
    surface = 2*pi*(d/2.)**2 + d*pi*h
    end

    subroutine vol(d,h,volume)
    real d,h,volume(count)
    volume(count) = h*pi*(d/2.)**2
    end
4

1 回答 1

2

对于有两个主程序的特殊问题,您可以通过替换 line 来消除它

      function circ(d) = d*pi

进入

      function circ(d)
      real circ
      real d
      circ = d*pi
      end

其他明显的问题是共享 pi,跨程序/函数/子例程计数。当您在运行时,您看不到主程序中的内容。最简单的解决方案是将它们与其他参数一起传递。在子程序 vol 中,

      volume(count) = h*pi*(d/2.)**2

为什么你有count

于 2011-11-16T02:56:42.093 回答