next up previous
Next: Input in Fortran Up: Assessment Previous: Assessment

Output in Fortran

In the previous chapter we discussed the way that a Fortran program can print to the terminal or to a file. These can be used to send messages to the person sitting in front of the computer. They can also be used to print values of variables.

      print *, shoulderx

It prints the value of the variable shoulderx to the terminal.

A single print statement can actually print several items at one time and all on one line. For example, the statement:

      print *, 'The answer to the problem is ', answer

prints two things: the text inside the single quote marks, followed by the value of the variable answer. Notice that there is a comma between the message string and the answer. This is required. When you want print to print more than one thing, you have to put commas between the things to be printed. Here are some more examples:

      print *, 'Contestant number ', num, ' has won ', amt, ' dollars.'
      print *, answer, ' is the answer.'

Take a look at the print statements in the rbtjnts.f program. Make sure that you understand what they all do.


J. C. Diaz