C      PROGRAMMER: Andrey Korsak
C      COURSE: CS 430
C      LANGUAGE: FORTRAN
C      COMPILER USED: FORCE 2.0
C      SOURCE FILENAME: BasePartA.f
C      EXECUTABLE FILENAME (IF ANY): BasePartA.f(NOT sumbmitted)
C      PROFESSOR: Professor Elizabeth S. Adams
C
C      DESCRIPTION OF THE PROGRAM'S PURPOSE:
C      The program is to get integer number in the range from 1 to
C      32767 and output inputed number to base 2.
C
C      DESCRIPTION OF THE PROGRAM'S REQUIRED INPUT:
C      Integer from 1 to 32767
C
C      DESCRIPTION OF THE PROGRAM'S EXPECTED OUTPUT:
C      Original integer from 1 to 32767.
C      Converted number in base 2.
C      Both output lines will have labels explaining what is outputed.
C
C      DESCRIPTION OF ANY MODIFICATIONS MADE IN DEBUGGING THE PROGRAM
C      None
C
C      GENERAL COMMENTS ABOUT THE PROGRAM
C      Program uses if statement and goto statement to create a while
C      loop. To convert from decimal to binary I use division algorithm
C      which uses division and remainders to convert decimal to binary.
C
C      GENERAL COMMNETS EXPLAINING THE FEATURES OF THE LANGUAGE
C      * IF (INT .NE. 0) GOTO 52 -  if statement which in which
C           if INT .NE. 0 evaluates to true we goto statement labeled 52
C           else we continue with the statement right under the IF
C           statement.
C      * MOD(INT, 2) - returns remainder when INT is divided by 2
C      * (BINARY(I), I = COUNTER - 1, 1, -1 ) - is an implied do loop
C            which prints numbers in binary(i) from counter -1 to 1
C      * FORMAT(1X, A, I6) - Says that print the data with one space
C            in front and then print string and finally print six digit
C            number. We are using five digit numbers so extra digit is
C            for the space in front of five digit number.


       PROGRAM BASEPARTA
       
       INTEGER BINARY(15)
       INTEGER INT, COUNTER
       COUNTER = 1

C      SAY HELLO TO USER AND GIVE INSTRUCTIONS
       WRITE(6, 99) 'Please enter decimal number from 1 to 32767:'
  99   FORMAT(1X, A)


C      READING THE INTEGER NUMBER FROM 1 TO 32767
       READ(5, 10) INT
 10    FORMAT(I5)
 
C      ECHO THE NUMBER USER HAS ENTERED
       WRITE(6, 41) 'The base 10 value of the input is:', INT
  41   FORMAT(/,1X, A, I6)
  
C      CONVERT FROM DECIMAL TO BINARY USING DIVISION ALGORITHM
  46   IF (INT .NE. 0) GOTO 52
       GOTO 60
  52   BINARY(COUNTER) = MOD(INT, 2)
       INT = INT / 2
       COUNTER = COUNTER + 1
       GOTO 46

C      OUTPUT THE BINARY NUMBER USING IMPLIED DO LOOP
  60   WRITE(6, 61) (BINARY(I), I = COUNTER - 1, 1, -1 )
  61   FORMAT(1X,'The base  2 value of the input is:',1X,15(15(I1)))
  
C      TELL USER PROGRAM IS OVER
       WRITE(6, 98) 'Program Ended!'
  98   FORMAT(/, 1X, A)
  
       STOP
       END
       

