C     Programmer: Josh Ginsburg
C     Course:    CS 430
C     Date Due:   Wednesday September 12, 2007 11:59pm
C     Language:  FORTRAN
C     Compiler used:  Force 2.0.8
C     Source Filename: PA2B.f
C     Executable Filename (if any) or None: PA2B.exe
C     Professor: Dr. Adams

C     Description of the program's PURPOSE:
C         Program which will read in a decimal number and print out
C          its base 2 representation. The base 10 decimal read in should
C          be echoed out with a label and the base 2 result should be
C          printed out with a label.

C      Description of program's required INPUT:
C         Read in a base 10 decimal number


C      Description of program's expected OUTPUT:
C          The inputted base 10 decimal should be outputted along
C          with the base 2  conversion of it.

C      Descriptions of any MODIFICATIONS made in debugging the program:
C            The majority spent of the debugging was getting the base
C           conversion algorithm to work properly, and also output in
C           the correct format

C      General COMMENTS about the PROGRAM
C           The program wasn't too dificult once I figured out the algorithm
C           and how to implement it.
C          Numbers are assumed to be positive
C          No error checking is performed

C      General COMMENTS explaining the syntax or features of the LANGUAGE
C         Being able to declare variables on the fly is a big help, but in
C        this case they all have to be REAL numbers so it doesn't.


C      Declare the variables to be used
       REAL I
       REAL SUM
       REAL POWER
       INTEGER COUNT
       
C      Output to user to enter a decimal number
       WRITE (6, 2)
2      FORMAT (1X, "Please enter a decimal number")

C      Read in the decimal number entered
       READ (5,4) I
       
C      format of the decimal number
4      FORMAT(F7.6)

C      Echo the decimal number entered
       WRITE (6, 6) I
       
C      format of the message and decimal number
6      FORMAT(1X, 'The base 10 value of the input is: ', F7.6)

C      Set the variables in the DO loop to zero, abd power to -1
       SUM = 0
       POWER = 0 - 1

C      Perform the DO loop 6 times
       DO 20 COUNT = 1, 6
       
C      Muliply the decimal by base 2 every time
       I = I * 2
       
C      If greater than or equal to 1, subtract 1 and take the remaining value
       IF ( I .GE. 1) go to 17
       
C      If less than 1 continue
       IF(I.LT.1) go to 18
       
C       Only add 10^POWER if I is greater than 1
17      SUM = SUM + ((10**POWER) )

C       Subtract 1 from I
        I = I - 1
        
C       Take the power to the next level
18      POWER = POWER - 1

C       continue the DO loop
20     CONTINUE

C       Output the converted decimal in base 2
       WRITE (6, 22) SUM
       
C       Format of the output
22     FORMAT(1X, 'The base 2 value of the input is: ', F7.6)

C       End the program
       END
