Hi,
Cobol is very new to me, and I still have problems with perform.
The purpose of this program is that it shows you the maximum and average temperature of each day, and the maximum temperature for that week.
But when I run this program, it won't stop when I type -1 (scope-terminator) for the day, and it always gives the temperature for monday. I really don't see what I'm doing wrong!
Can anyone help me, please?
Thx
Cobol is very new to me, and I still have problems with perform.
The purpose of this program is that it shows you the maximum and average temperature of each day, and the maximum temperature for that week.
But when I run this program, it won't stop when I type -1 (scope-terminator) for the day, and it always gives the temperature for monday. I really don't see what I'm doing wrong!
Can anyone help me, please?
Thx
Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. examen.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 temperature.
03 wday occurs 7.
05 dayname pic x(10).
05 max pic s99 value -99.
05 sum pic s999 value 0.
05 counter pic 99 value 0.
05 av pic s99v9.
77 daynumber pic s9.
88 number value 1 thru 7.
77 temp pic s99.
77 hday pic 9.
77 tempmax pic s99.
* 77 av pic s99v9.
77 dav pic +99.9.
77 i pic 9.
77 line pic x(30) value "-".
PROCEDURE DIVISION.
hoofd.
PERFORM init
PERFORM TEST AFTER UNTIL (daynumber = -1)
PERFORM readday
PERFORM readtemp
END-PERFORM
PERFORM calcav
PERFORM detmax
PERFORM output
STOP RUN.
init.
MOVE "monday" TO dayname(1)
MOVE "tuesday" TO dayname(2)
MOVE "wednessday" TO dayname(3)
MOVE "thursday" TO dayname(4)
MOVE "friday" TO dayname(5)
MOVE "saturday" TO dayname(6)
MOVE "sunday" TO dayname(7).
* read the daynumber
readday.
PERFORM TEST AFTER UNTIL (daynumber = -1 OR number)
DISPLAY "Give daynumber, -1 to stop"
ACCEPT daynumber NO BEEP
END-PERFORM
IF (daynumber = -1)
THEN perform calcav
END-IF.
* read the temperature for that day
readtemp.
MOVE 1 TO daynumber
DISPLAY "Give temperature for this day"
ACCEPT temp NO BEEP
COMPUTE sum(daynumber) = sum(daynumber) + temp
COMPUTE counter(daynumber) = counter(daynumber) + 1
IF temp > max(daynumber)
THEN MOVE temp TO max(daynumber)
END-IF.
* calculate the average temperature
calcav.
MOVE 1 TO daynumber
PERFORM UNTIL (daynumber > 7)
COMPUTE av(daynumber) = sum(daynumber) /
- counter(daynumber)
ADD 1 TO daynumber
END-PERFORM.
* determine the maximum temperature for that day
detmax.
MOVE 2 TO daynumber
PERFORM UNTIL (daynumber > 7)
IF max(daynumber) > max(daynumber - 1)
THEN MOVE max(daynumber) TO tempmax
MOVE dagnaam(daynumber) TO hdag
END-IF
COMPUTE daynumber = daynumber + 1
END-PERFORM.
output.
MOVE 1 TO daynumber
DISPLAY "day max average"
DISPLAY line
PERFORM UNTIL (daynumber > 7)
MOVE av(daynumber) TO dav
DISPLAY dayname(daynumber) max(daynumber) dav
END-PERFORM
DISPLAY line
DISPLAY "The warmest day was" hdag "with" tempmax "degrees".