C     Programmer: Chris Golding
C     Course: CS 430
C     Date Due: 9/13/07
C     Languate: Fortran
C     Compiler Used: Force 2.0
C     Executable File Name: PA2-B.exe
C     Professor: Adams

C     Description of the program's PURPOSE:
C     To read user inputed base 10 values between 0 and 1 and convert it
C     to base 2 and then output it to the user.

C     Description of the program's required INPUT:
C     The user will input a decimal number between 0 and 1.

C     Descriptoin of the program's expected OUTPUT:
C     The program will echo the user's inputed base 10 value and then
C     output the value in base 2.

C     Descrptions of any MODIFICATIONS made in debugging the program:
C     Initially I had created the array that held the binary values,
C     as an array of reals but this did not function so I switched it
C     to an array of Intergers.

C     Gernal COMMENTS about the PROGRAM:
C     No error checking is performed
C     The program exits on successful run.

C     General COMMENTS explaining the syntax or features of the LANGUAGE
C     This program required me to examine, the use of using IF statements
C     without the use of the ENDIF.

      DIMENSION N(15)   !Initializes array of Integers

      MAXLENGTH = 6     !Sets maximum length of output

      WRITE (6, 10)              !Prompt for input
      READ (5, 21) USERINPUT     !Reads user input

C     Chescks the user inputed values validity
      IF (USERINPUT.LT.1.AND.USERINPUT.GT.0) GO TO 4
      WRITE (6, 25)                     !Outputs error message
      GO TO 5                           !Exits application

   4  WRITE (6, 24) USERINPUT           !Echos user inputed value

C     Converts user inputed base 10 value to base 2 using the
C     multiplication conversion method.
      DO 30 I=1, MAXLENGTH
         USERINPUT = USERINPUT * 2
         IF (USERINPUT.GE.1) GO TO 7
         N(I) = 0
         GO TO 30
   7     N(I) = 1
         USERINPUT = USERINPUT - 1
 30   CONTINUE

      ISTOP = 1        !Array location where end of binary number occurs
C     Method for removing extra 0s from binary output
      DO 31 I=1, 15
         IF (N(I).EQ.1) ISTOP = I
 31   CONTINUE

      WRITE (6, 23) (N(I), I=1,ISTOP)   !Outputs base 2 number


C     Format satements for the input and output
 10   FORMAT (1X, "WELCOME PLEASE ENTER A NUMBER BETWEEN 0 AND 1")
 21   FORMAT (F7.6)
 23   FORMAT (/1X, "THE BASE 2 VALUE OF THE INPUT IS: .", 6I1)
 24   FORMAT (1X, "THE BASE 10 VALUE OF THE INPUT IS: ",  F7.6)
 25   FORMAT (/1X, "THE VALUE ENTERED IS NOT A VALID VALUE.")

 5    STOP
      END
