Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *> Display the average of the five highest temperatures for five cities.
- *> GNU-COBOL
- *> Free format
- PROGRAM-ID. TEMPERATURE.
- DATA DIVISION.
- WORKING-STORAGE SECTION.
- 01 CITY OCCURS 5 TIMES INDEXED BY CITY-ID.
- 05 CITY-NAME PIC X(10).
- 05 CITY-TEMP PIC 99V9 OCCURS 5 TIMES INDEXED BY TEMP-ID.
- 77 COUNTER PIC 9.
- 77 AVG-CITY-TEMP PIC 99.9 OCCURS 5 TIMES.
- 77 SUM-OF-TEMP PIC 999V9.
- SCREEN SECTION.
- 01 CLEAR-SCREEN.
- 05 BLANK SCREEN.
- 01 CITIES-DATA.
- 05 VALUE "Enter the last 5 daily hight temperature for:" LINE 1 COL 1.
- 05 CITY-NAME-INPUT COL 47 PIC X(10) TO CITY-NAME(CITY-ID) AUTO.
- 05 VALUE "Temperatures:" LINE 3 COL 1.
- 05 VALUE "Temperature #1: " LINE 4 COL 1.
- 05 TEMP1_INPUT PIC 99.9 COL 17 TO CITY-TEMP(CITY-ID, 1) AUTO.
- 05 VALUE "Temperature #2: " LINE 5 COL 1.
- 05 TEMP2_INPUT PIC 99.9 COL 17 TO CITY-TEMP(CITY-ID, 2) AUTO.
- 05 VALUE "Temperature #3: " LINE 6 COL 1.
- 05 TEMP3_INPUT PIC 99.9 COL 17 TO CITY-TEMP(CITY-ID, 3) AUTO.
- 05 VALUE "Temperature #4: " LINE 7 COL 1.
- 05 TEMP4_INPUT PIC 99.9 COL 17 TO CITY-TEMP(CITY-ID, 4) AUTO.
- 05 VALUE "Temperature #5: " LINE 8 COL 1.
- 05 TEMP5_INPUT PIC 99.9 COL 17 TO CITY-TEMP(CITY-ID, 5).
- 01 CITIES-DISPLAY BLANK SCREEN.
- 05 VALUE "Here are the average temperatures for cities in the area" LINE 1 COL 1.
- 05 FROM CITY-NAME(1) PIC X(10) LINE 3 COL 10.
- 05 FROM CITY-NAME(2) PIC X(10) COL 20.
- 05 FROM CITY-NAME(3) PIC X(10) COL 30.
- 05 FROM CITY-NAME(4) PIC X(10) COL 40.
- 05 FROM CITY-NAME(5) PIC X(10) COL 50.
- 05 FROM AVG-CITY-TEMP(1) PIC 99.9 LINE 4 COL 10.
- 05 VALUE "C" COL 15.
- 05 FROM AVG-CITY-TEMP(2) PIC 99.9 COL 20.
- 05 VALUE "C" COL 25.
- 05 FROM AVG-CITY-TEMP(3) PIC 99.9 COL 30.
- 05 VALUE "C" COL 35.
- 05 FROM AVG-CITY-TEMP(4) PIC 99.9 COL 40.
- 05 VALUE "C" COL 45.
- 05 FROM AVG-CITY-TEMP(5) PIC 99.9 COL 50.
- 05 VALUE "C" COL 55.
- PROCEDURE DIVISION.
- P1.
- PERFORM P-CITY-LOOP VARYING CITY-ID FROM 1 BY 1 UNTIL CITY-ID > 5
- DISPLAY CLEAR-SCREEN
- DISPLAY CITIES-DISPLAY
- GOBACK.
- P-CITY-LOOP.
- INITIALIZE CITIES-DATA
- DISPLAY CITIES-DATA
- ACCEPT CITIES-DATA
- PERFORM CALCULATE-TEMP.
- CALCULATE-TEMP.
- INITIALIZE SUM-OF-TEMP
- PERFORM VARYING TEMP-ID FROM 1 BY 1 UNTIL TEMP-ID > 5
- ADD CITY-TEMP(CITY-ID, TEMP-ID) TO SUM-OF-TEMP
- END-PERFORM
- DIVIDE SUM-OF-TEMP BY 5 GIVING AVG-CITY-TEMP(CITY-ID).
- END PROGRAM TEMPERATURE.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement