C     Programmer: Wesley Wenger
C     Course: CS 430
C     Date Due: September 12, 2007
C     Language: FORTRAN
C     Compiler used: FORCE2.0.8
C     Source Filename: P2partB
C     Executable Filename (if any) or None: P2partB
C     Professor: Elizabeth Adams
C     Purpose: To convert base 10 to binary base 2
C     Input: A fraction
C     Output:  The output will be the original number and its binary
C     equivalent
C     Language  Information
C     All the variables in ths program are real because their names begin
C     with letters A-H, or O-Z the variables don't need to be declared
C     because they are by default real
C     WRITE is the output statement
C     6 in WRITE (6,_) is the default output device
C     the numbers after  6,  in the WRITE statements are the labels for
C     the related FORMAT statements
C     FORMAT statements are not executable and may be placed anywhere in the program
C     The F format indicates a real number is to be output.
C     The 2nd number after the F in the FORMAT statement indicates numer of
C     places after the decimal point
C     The STOP statement ends the program execution
C     The END statement marks the end of a compilation unit

C     PART B - Takes in a fraction between 0 and 1 and converts it to
C     base 2 by multiplying by 2 and looking at the value

C     The array that holds the value of the base 2 equivalent
      INTEGER FARRAY(100)
      
C     Prompts the user for a value and takes in the value
      WRITE (6, 12) "Enter a fraction in base 10(between 0 and 1): "
  12  FORMAT (1X,A45)
      READ (5,10)  FRACTION
  10  FORMAT (F10.3)

C     Prints the original value and the header
      WRITE (6,15) 'The base 10 value of the input is:  ', FRACTION
  15  FORMAT (///1X, A35, F4.3)

C     Do Loop that calculates the value in base 2 and assigns it to an
C     array.  INDEX shows how long the value is in the case that it is
C     less than 6 digits.  This allows for a clean printout. FRACTION is
C     the value input by the user.  FARRAY is the array where the array
C     the values are stored.
      INDEX = 0
      DO 8 K = 1,6
         FRACTION = FRACTION*2
         INDEX = INDEX+1
         IF(FRACTION.GE.1) FARRAY(K) = 1
         IF(FRACTION.LT.1) FARRAY(K) = 0
         IF(FRACTION.EQ.1) GOTO 13
         IF(FRACTION.GT.1) FRACTION = FRACTION-1
   8  CONTINUE

C     Writes out the values of the array with a header
C     preceded by a decimal point
  13  WRITE (6,11) 'The base 2 value of the input is: .' ,
     C (FARRAY(I), I = 1,INDEX)
  11  FORMAT(1X, A35, 7I1)
      STOP
      END








