C       Programmer: Blaine Whited
C       Course: 430
C       Date Due: September 12th, 2007
C       Language: FORTRAN
C       Compiler used: FORCE 2.0
C       Source Filename: PA2B.f
C       Executable Filename (if any) or None: PA2B.exe
C       Professor:  Dr. Elizabeth S. Adams
C
C       Description of the program's PURPOSE:
C           This program will read in a decimal base 10 and convert it
C           to base two displaying only 6 decimal places
C       Description of program's required INPUT:
C           A decimal number in base 10 to convert to base 2
C       Description of program's expected OUTPUT:
C           A binary representation of the base 10 in base 2 using 6
C           decimal places
C       Descriptions of any MODIFICATIONS made in debugging the program:
C           I underestimated part b (this part) and didn't start early
C           enought to debug it, with some extra time, I surely would
C           have been able to convert and print correctly.
C       General COMMENTS about FORTRAN
C           It is annoying to work around FORTRAN's shortcomings in
C           Integer storage.
C       General COMMENTS explaining the syntax or features of the
C         LANGUAGE
C           Fortran formatting is not very intuitive. It seems like the
C           formats for writes are hit or miss when it gets complicated.

C     initialize the storing array (6 for the 6 decimal places per
C     specifications)
      DIMENSION IRESULT(6)
      A = 0

C     Write the opening message
      WRITE(6,1)
    1 FORMAT(1X,'Welcome to the magnificent decimal base converter.')
C     Line label is used to check for proper inputs
   51 WRITE(6,2)
    2 FORMAT(1X,'This program will attempt to convert an integer')
      WRITE(6,3)
    3 FORMAT(1X,'between 1 and 32767 into its binary equivalent.')
      WRITE(6,4)
    4 FORMAT(1X,'Please enter an decimal now')

C     Reads the inputted value and stores it in the variable IA
      READ (5,5) A
    5 FORMAT (F30.30)

C     Says "If the inputted value is less than 0 or the inputted value
C     is greater than 1 goto 52"
      IF (A .LT. 0 .OR. A .GT. 1) GO TO 52
C     Says "When the IF fails, skip the next printout"
      GO TO 60
C     Says "When the IF passes, print out an error message and ask for
C     another input."
   52 WRITE(6,6)
    6 FORMAT(1X,'Please, only enter numbers between 1 and 0')
      GO TO 51

C     Echos the inputted value
   60 WRITE(6,7) A
    7 FORMAT(1X,'You input: ', F30.30)

C     Begin conversion
C     Loops though all 6 binary digits
      DO 112 I = 1,6

C     Initializes each integer of the array
      IRESULT(I) = 0

C     Resets the binary value holder to 0
      IB = 0

C     Does the mathematics to the inputted value one binary digit at a
C     time, says "if the value left is less than 1/2**I skipp this
C     value, otherwise, make the array location equal to 1, and subtract
C     it from the inputted number
      IF((A-(1/(2**I))) .LT. 0) GOTO 112
      IRESULT(I) = 1
      A = A-(1/(2**I))

C     Saves the result in the array
      IRESULT(I) = IB

C     End of DO Loop
  112 CONTINUE


C     Prints out the binary number, with labeling.
      WRITE (6, 24) (IRESULT(K), K=1,6)
   24 FORMAT (1X, 'That number in binary is: .',6(I1))

C     Finishes the program with an exit print out
      WRITE(6,100)
  100 FORMAT(1X, 'Thank you for using our software.')

C     End of the program
      STOP
      END
