Computers in Engineering WWW Site - Example 3.5

# Example 3.5

#### FORTRAN Version

```!
PROGRAM P36
!
!     Nested IF blocks
!
IMPLICIT NONE
LOGICAL :: SINGLE
CHARACTER (LEN=20) :: NAME
INTEGER :: I,J,AGE,N,TAGE
REAL :: AVE
!
!
PRINT *, 'This is Program >> P36  - Nested IF blocks'
!
!
!
N=0
TAGE=0.0
L1:      DO J=1,I
PRINT * ,NAME,SINGLE,AGE
IF(SINGLE)THEN
N=N+1
TAGE=TAGE+AGE
IF(N  ==  5)THEN
AVE=TAGE/5.0
PRINT * ,'AVERAGE AGE OF ', &
'FIRST FIVE SINGLES IS'
PRINT * ,AVE
STOP
END IF
END IF
END DO L1
STOP
END PROGRAM P36
```
DATA:
```7
'Bruce Perras'         T  17.0
'Donna Smith'          F  23.0
'Suzie Gascon'         T  19.0
'Mary Brown'           T  22.0
'Jane Jones'           T  35.0
'Sophie Rochon'        F  29.0
'Alex Reid'            T  25.0
```
OUTPUT:
```
+--------------------------------------------------+
|     32-bit Power for Lahey Computer Systems      |
|   Phar Lap's 386|DOS-Extender(tm) Version 7.0    |
|  Copyright (C) 1986-94 Phar Lap Software, Inc.   |
|           Available Memory = 14880 Kb            |
+--------------------------------------------------+

This is Program >> P36  - Nested IF blocks
Bruce Perras         T          17
Donna Smith          F          23
Suzie Gascon         T          19
Mary Brown           T          22
Jane Jones           T          35
Sophie Rochon        F          29
Alex Reid            T          25
AVERAGE AGE OF FIRST FIVE SINGLES IS
23.6000
```

#### Pascal Version

```PROGRAM p36 (input, output);
VAR
single : BOOLEAN;
single_tmp, n : INTEGER;
name : STRING[20];
tage, age, ave : REAL;
BEGIN
n := 0;
tage := 0.0;
readln ( name, single_tmp, age );
WHILE ( n < 5 ) DO
BEGIN
IF ( single_tmp = 1 ) THEN single := true;
IF ( single_tmp = 0 ) THEN single := false;
IF single THEN
BEGIN
n := n + 1;
tage := tage + age;
IF ( n = 5 ) THEN
BEGIN
ave := tage/5.0;
writeln ( 'average age of first five singles is ' );
writeln ( ave )
END { end if }
END; { end if }
readln ( name, single_tmp, age )
END { end while }
END.
```
DATA:
```Bruce Perras         1  17.0
Donna Smith          0  23.0
Suzie Gascon         1  19.0
Mary Brown           1  22.0
Jane Jones           1  35.0
Sophie Rochon        0  29.0
Alex Reid            1  25.0
```