module typefy
 type students
  integer :: height ,weight,chinese,english ,fortran,history,num,sex
  integer :: total
  real    :: average
  end type
end module

program main
 implicit none
  call message()
 stop
end program

subroutine message()
 use typefy
  implicit none
 type(students),dimension(20) :: s
 type(students)               :: temp
 type(students)               :: total
 integer                      :: i,j,sex,error,real
 integer                      :: num
 integer                      :: a,b,c,d,r
 integer                      :: sum1=0,sum2=0
 character(len=80)            :: aaa
   open(111,file="exam.txt",status="old",iostat=error)
      if (error/=0)then
        write(*,*) "Open exam.txt fail."
       stop
      end if

    read(111,"(A100)")aaa
     do i=1,20
       read(111,*)s(i)%num ,s(i)%sex ,s(i)%height ,s(i)%weight ,s(i)%chinese ,s(i)%english ,s(i)%fortran,s(i)%history
        s(i)%total=s(i)%chinese+s(i)%english+s(i)%fortran+s(i)%history
        s(i)%average=(s(i)%total)/4.0
        total%Height=total%Height+s(i)%height
        total%Weight=total%Weight+s(i)%weight
         if(s(i)%sex=="0") then  !0表示女生,1表示男生
          s(i)%total=s(i)%chinese+s(i)%english+s(i)%fortran+s(i)%history
          s(i)%average=(s(i)%total)/4.0
         end if

     end do

     write(*,"(10A8)")"num","sex","height","weight","chinese","english","fortran","history","total","average"
      do i=1,20
       write(*,"(9I8,f8.2)")s(i)%num ,s(i)%sex ,s(i)%height ,s(i)%weight ,s(i)%chinese ,s(i)%english ,&
                                 s(i)%fortran,s(i)%history,s(i)%total,s(i)%average
      end do
 write(*,*)"averageHeight,weight",&
 real(total%Height)/20.0,&
 real(total%Weight)/20.0

 do i=1,19
  do j=i+1,20
   if(s(i)%total.le.s(j)%total) then
    temp=s(i)
    s(i)=s(j)
    s(j)=temp
   endif
 end do
end do

write(*,"(A3,A9,A6,2A9,A8,A9)")"num","chinese","english","fortran","history","total","average"
 do i=1,8
  write(*,"(I3,3I7,I8,I10,f8.2)")s(i)%num ,s(i)%chinese ,s(i)%english ,s(i)%fortran ,s(i)%history ,s(i)%total ,s(i)%average
 end do

write(*,"(A6,A6,A4)")"sum1","sum2","r"
 i=1
do while(i<=20)
 a=(s(i)%height)-(real(total%Height)/20.0)
 b=(s(i)%weight)-(real(total%Weight)/20.0)
 c=a*b
 d=((a*a)**0.5)*((b*b)**0.5)
 sum1=sum1+c
 sum2=sum2+d
 i=i+1
end do[/color][/color]write(*,"(f6.2,f6.2,f6.2)")sum1,sum2,sum1/sum2

stop

end subroutine



 type students
  integer :: height ,weight,chinese,english ,fortran,history,num,sex
  integer :: total
  real    :: average
  end type
end module

program main
 implicit none
  call message()
 stop
end program

subroutine message()
 use typefy
  implicit none
 type(students),dimension(20) :: s
 type(students)               :: temp
 type(students)               :: total
 integer                      :: i,j,sex,error,real
 integer                      :: num
 integer                      :: a,b,c,d,r
 integer                      :: sum1=0,sum2=0
 character(len=80)            :: aaa
   open(111,file="exam.txt",status="old",iostat=error)
      if (error/=0)then
        write(*,*) "Open exam.txt fail."
       stop
      end if

    read(111,"(A100)")aaa
     do i=1,20
       read(111,*)s(i)%num ,s(i)%sex ,s(i)%height ,s(i)%weight ,s(i)%chinese ,s(i)%english ,s(i)%fortran,s(i)%history
        s(i)%total=s(i)%chinese+s(i)%english+s(i)%fortran+s(i)%history
        s(i)%average=(s(i)%total)/4.0
        total%Height=total%Height+s(i)%height
        total%Weight=total%Weight+s(i)%weight
         if(s(i)%sex=="0") then  !0表示女生,1表示男生
          s(i)%total=s(i)%chinese+s(i)%english+s(i)%fortran+s(i)%history
          s(i)%average=(s(i)%total)/4.0
         end if

     end do

     write(*,"(10A8)")"num","sex","height","weight","chinese","english","fortran","history","total","average"
      do i=1,20
       write(*,"(9I8,f8.2)")s(i)%num ,s(i)%sex ,s(i)%height ,s(i)%weight ,s(i)%chinese ,s(i)%english ,&
                                 s(i)%fortran,s(i)%history,s(i)%total,s(i)%average
      end do
 write(*,*)"averageHeight,weight",&
 real(total%Height)/20.0,&
 real(total%Weight)/20.0

 do i=1,19
  do j=i+1,20
   if(s(i)%total.le.s(j)%total) then
    temp=s(i)
    s(i)=s(j)
    s(j)=temp
   endif
 end do
end do

write(*,"(A3,A9,A6,2A9,A8,A9)")"num","chinese","english","fortran","history","total","average"
 do i=1,8
  write(*,"(I3,3I7,I8,I10,f8.2)")s(i)%num ,s(i)%chinese ,s(i)%english ,s(i)%fortran ,s(i)%history ,s(i)%total ,s(i)%average
 end do

write(*,"(A6,A6,A4)")"sum1","sum2","r"
  i=1
do while(i<=20)
 a=(s(i)%height)-(real(total%Height)/20.0)
 b=(s(i)%weight)-(real(total%Weight)/20.0)
 c=a*b
 d=((a*a)**0.5)*((b*b)**0.5)
 sum1=sum1+c
 sum2=sum2+d
 i=i+1
end do
write(*,"(f6.2,f6.2,f6.2)")sum1,sum2,sum1/sum2

stop

end subroutine


do while这段,系统检测不出错误,但是输出的结果都是0.00,,,这是为什么!!求高手指导!