!  Program to calculate the normal and false mean
!  Jim Crumley
!  20031007

Program mean

    implicit none
    integer, parameter :: max_size=100
    real :: nums(max_size)=0.0, mean1, mean2, false_mean, minn, maxx, mean3=0
    real :: temp
    integer :: numnums, i  
    logical :: done=.false.
  
    print *, "Enter the number of values that you would like to calculate the&
      & mean of:"
    read *, numnums

    print *, "Enter the original numbers:"
    read *, nums(1:numnums) 
    print *, nums(1:numnums)
   
    mean1 = sum(nums(1:numnums))/numnums         ! mean found the simple way

    print *, "Enter your false mean:"
    read *, false_mean
    print *, false_mean

    print *, "Enter the numbers with the false mean removed:"
    read *, nums(1:numnums)
    print *, nums(1:numnums)
    

    if (false_mean >= 0 ) then
        temp = sum (nums(1:numnums))/numnums 
        mean2 = temp + false_mean
    else
        temp = sum (nums(1:numnums))/numnums 
        mean2 = temp - false_mean
    endif

    print "(A,f11.3,A)", " The mean calculated directly is", mean1, ","
    print "(A, f11.3)", " while using a false mean of ", false_mean
    print "(A, f11.3, A)",  " gives a mean of", mean2, "."
    print *, "The part combined with the false mean was", temp, "," 
    print *,"and the difference between the direct mean and the false mean was"&
       ,mean1 - false_mean, "."

End Program mean
