C     Programmer:  Stephen Anderson
C     Course:  CS430, Section 0001
C     Date Due:  September 13, 2007
C     Language:  FORTRAN 77
C     Compiler used:  Force 2.0
C     Source Filename:  Project2B.f
C     Executable Filename (if any) or None:  None
C     Professor:  Dr. Adams

C     Description of the program's PURPOSE:
C      Reads a BASE 10 decimal number and prints the representation
C      of the decimal number in BASE 2

C     Description of program's required INPUT:
C      The input must be an decimal.
C      The decimal value has to be between 0 and 1.
C      The decimal value can only be to the 6th decimal place.


C     Description of program's expected OUTPUT:
C      The output will print off the input decimal in BASE 10 followed
C      by the decimal's representation in BASE 2, which is binary.

C     Descriptions of any MODIFICATIONS made in debugging the program:
C      The original program had the value INPUT used in the entire
C      program.  But changing INPUT in the DO-LOOP messed up the output
C      so  INPUT is assigned to another value called DECIMAL
C      and DECIMAL is the value manipulated during the DO-LOOP.

C     General COMMENTS about the PROGRAM:
C      The input has to be an decimal value and between 0 and 1.
C      The program reads in the input value.  A 0 is stored in each
C      index of the array.
C      Inside a DO-LOOP, the copied input value, DECIMAL, is doubled.
C      The loop then checks if the value is equal or greater than
C      1.0.  If the value is equal or greater than 1.0, then the 0 in
C      BINARY(I) is replaced with 1.  1.0 is then subtracted from
C      DECIMAL.  If DECIMAL is less than 1.0, the DO-LOOP will not
C      change the value in BINARY or change the value of DECIMAL.
C      The array is then printed off from index 1 to 6 to give the
C      representation of the decimal in BASE 2.

C     General COMMENTS explaining the syntax or features of the LANGUAGE
C      The array that holds the BASE 2 (binary) representation is
C      an integer array, is called BINARY, and has a size of 6.
C      The decimal value, INPUT, is the input value in BASE 10.
C      INPUT is copied into DECIMAL and the value of DECIMAL is
C      changed inside the DO-LOOP.

C      The WRITE statements have 2 numbers in parenthesizes.  The first
C      number is the default output device and the second number is the
C      number associated with the FORMAT statement for the WRITE.
C      The FORMAT statements associated with the WRITE statements have
C      different statements in the parenthesizes.  A statement like A43
C      means character format and has a length of 43.  F7.6 is a decimal
C      number 7 spaces long and has 6 values in the decimal region.
C      A statement I1 means an integer, 1 digit long.  1X is one space.

C      The READ statement has 2 numbers.  The 5 is the default input
C      device and the second number is the number associated with the
C      FORMAT statement.

C      In the DO-LOOPS, the value I is the counter for each loop and is
C      also used as the index of the BINARY array.

C      In the second DO-LOOP, the first IF statement checks to see
C      if DECIMAL is greater than or equal to 1.0.  It also creates
C      the BASE 2 representation of the decimal value.


C      Declaration of the INTEGER array and the REAL values
       INTEGER BINARY(6)
       REAL INPUT, DECIMAL

C      Prompts and reads the input value and stores it in INPUT
       WRITE (6,21) 'Please enter a decimal number less than 1.0.'
  21   FORMAT (A43)
       READ (5,22) INPUT
  22   FORMAT (F7.6)

C      Prints out the input value
       WRITE (6,23) 'The base 10 value of the input is: ', INPUT
  23   FORMAT (1X/(A35, F7.6)/1X)

C      Assigns each index of the array as 0
       DO 24 I = 1, 6, 1
          BINARY(I) = 0
  24   CONTINUE

C      The value in INPUT is assigned to DECIMAL
       DECIMAL = INPUT

C      Checks where the values of 1 are for the BASE 2 representation
       DO 25 I = 1,6,1
          DECIMAL = DECIMAL * 2.0
          IF ((DECIMAL .EQ. 1.0) .OR. (DECIMAL .GT. 1.0))
     C       BINARY(I) = 1
          IF (BINARY(I) .EQ. 1)
     C       DECIMAL = DECIMAL - 1.0
  25   CONTINUE

C      Prints out the BASE 2 representation of the input value
       WRITE (6,51) 'The base 2 value of the input is: .',
     C (BINARY(I), I = 1,6,1)
  51   FORMAT (A35, 6(I1))

       STOP
       END
