< Programming Fundamentals < Arrays
arrays.cbl
*> This program uses an array to calculate and display a
*> Celsius to Fahrenheit temperature conversion table.
*>
*> References:
*> https://www.tutorialspoint.com/cobol/index.htm
*> https://open-cobol.sourceforge.io/doc/gnucobol.html
IDENTIFICATION DIVISION.
PROGRAM-ID. ARRAYS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CELSIUS.
05 CELSIUS-VALUE PIC 9(3)v9(2) OCCURS 100 TIMES INDEXED BY C.
01 CELSIUS-OUT PIC Z(2)9.
01 FAHRENHEIT-OUT PIC Z(2)9.99.
PROCEDURE DIVISION.
MAIN.
PERFORM CALCULATE-CELSIUS VARYING C FROM 1 BY 1 UNTIL C > 100.
PERFORM DISPLAY-CELSIUS VARYING C FROM 1 BY 1 UNTIL C > 100.
STOP RUN.
CALCULATE-CELSIUS.
COMPUTE CELSIUS-VALUE(C) = C * 9 / 5 + 32.
DISPLAY-CELSIUS.
MOVE C TO CELSIUS-OUT.
MOVE CELSIUS-VALUE(C) TO FAHRENHEIT-OUT.
DISPLAY CELSIUS-OUT "° Celsius is " FAHRENHEIT-OUT "° Fahrenheit".
Try It
Copy and paste the code above into one of the following free online development environments or use your own COBOL compiler / interpreter / IDE.
See Also
This article is issued from Wikiversity. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.