0

私が書いたこのプログラムをコンパイルするのに問題があります。問題が何であるかを把握するために何時間も費やしましたが、まったく役に立たない2つの主要なプログラムがあるとだけ言っています。どんな助けにもとても感謝しています。ありがとう

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

2つのメインプログラムがあるという特定の問題については、行を置き換えることでそれを取り除くことができます

      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 に答える