C       Programmer: Christopher Flint
C       Course: CS 430
C       Date Due:  9/13/07
C       Language:  Fortran
C       Compiler used:  Force 2.0
C       Source Filename:  DecimalFlint.f
C       Executable Filename (if any) or None:  DecimalFlint.exe
C       Professor:   Adams
C
C       Description of the program's PURPOSE:
C       This program is designed to read in a decimal fraction and output its binary notation.
C
C       Description of program's required INPUT:
C       Reads in a decimal fraction from the keyboard.
C
C       Description of program's expected OUTPUT:
C       Outputs prompts, echoes base 10 number inputed, and displays base 2 number converted.
C
C       General COMMENTS about the PROGRAM
C       This program is fairly straight forward.

C       This is the block of Format Texts.
  10   FORMAT("Please enter a base 10 Decimal")
  11   FORMAT('The base 10 value of the input is: ', F6.5)
  12   FORMAT('The base 2 value of the input is: .', 6I1)
  13   FORMAT('The program has ended successfully.')
  14   FORMAT('The number must be an integer between 0 and 1')
  20   FORMAT(F5.5)

C      This is where all the variable are initialized.
       REAL TEN
       REAL TEN2
       REAL STEP
       INTEGER BINARY(6)

C      This is the code to read in the number and check that it's right.
  70   WRITE(6,10)
       READ(5,20, ERR = 71) TEN
       IF (TEN .LT. 1 .AND. TEN .GT. 0) GOTO 72
  71   WRITE(6,14)
       GOTO 70

C      This code runs a Do Loop to find the binary notation of the number.
  72   TEN2 = TEN
       DO 73 I = 1,6
          STEP = 1/(2.0**I)
          IF (TEN2 .LT. STEP) GOTO 74
          BINARY(I) = 1
          TEN2 = TEN2 - STEP
          GOTO 73
  74      BINARY(I) = 0
  73   CONTINUE
  
C      This block of code prints the echo and the input number in binary notation.
       WRITE(6,11)TEN
       WRITE(6,12)(BINARY(I), I = 1,6)
       WRITE(6,13)
       STOP
       END
