Next: Checkoff
Up: Arithmetic Expressions
Previous: INTEGER vs. REAL

Declarations

Fortran's convention of determining the types of variables from their first letter dates from the 1950's. But this convention can be easily forgotten, especially by beginning programmers, when writing programs. The result can be a program in which the variables are not of the types intended by the programmer.

Fortunately, Fortran provides a solution to this possible pitfall and you should take advantage of it. We have created a third program that demonstrates this solution. See ``examples/average3.f'' (or view it directly).

Notice that near the beginning of the program we have explicitly declared the types of I and J. This overrides the convention that would otherwise treat I and J as integers. Compile and run the program now---does it work?

Click here for explanation

It is so important to declare variables explicitly that Fortran provides a way of checking that you have done so. Modify the example program by adding the line

IMPLICIT NONE

immediately before the line with the declarations of I and J. Now try to compile the program. What do you see?

Click here for explanation

Add a declaration for K and try compiling and running the program again. This time it should work.

You should get in the habit of using ``IMPLICIT NONE'' in all of your programs. In fact, it is so important that we will require that you do so in this class.


Next: Checkoff
Up: Arithmetic Expressions
Previous: INTEGER vs. REAL

Hamlet Project
hamlet@cs.utah.edu