Fortran_Lecture_2

Fortran_Lecture_2 - Lecture 2 User Input, Advanced IF...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 2 – User Input, Advanced IF Statements, and Fortran Formatting Let’s look at a more sophisticated program that incorporates user input. This time, we’ll let the program keep running cases until the user has had enough school spirit. program test2 ! This is a test program to show how programming logic works. 36832 write(*,*) ‘Enter a number from 0 to 3.’ read(*,*) i if (i.eq.0) write(*,*) ‘AUBURN’ if (i.eq.1) write(*,*) ‘TIGERS’ if (i.eq.2) write(*,*) ‘WAR’ if (i.eq.3) write(*,*) ‘EAGLE’ write(*,*) ‘Are you ready for more school spirit?’ write(*,*) ‘Enter 1 for yes or 2 for no.’ read(*,*) j if (j.eq.1) goto 36832 stop end Note the location label in the left margin and the new “goto” statement. If j is equal to 1 after the second request, the program will go back up to the first request, essentially starting the whole thing over again. The program has no knowledge of how many times it has gone through this process, and it doesn’t care. The “read” and “write” statements are very similar to each other. The “(*,*)” part is a quirk of Fortran’s syntax. The first part determines where the information will be read from or written to, while the second part determines the formatting that will be applied to that information. The star tells the program to use the default settings, which is the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Fortran_Lecture_2 - Lecture 2 User Input, Advanced IF...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online