Friday, August 12, 2016

Math Calculator in Cobol

Here is a simple program that I wrote using COBOL to imitate a very simple calculator. The program will ask the user to give two numbers and then our program will compute for the sum, difference, product and quotient of the two numbers given by our user. I am using OpenCOBOLIde as my compiler in this sample program. I hope you will like it. Thank you.


Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

******************************************************************

* Author: MR. JAKE R. POMPERADA

* Date: AUGUST 12, 2016

* Purpose: MATH CALCULATOR IN COBOL

******************************************************************

IDENTIFICATION DIVISION.

PROGRAM-ID. CALCULATOR.

DATA DIVISION.

WORKING-STORAGE SECTION.

77 NUM_1 PIC 9(4).

77 NUM_2 PIC 9(4).

77 SOLVE_SUM PIC 9(4).

77 SOLVE_DIFF PIC 9(4).

77 SOLVE_PRODUCT PIC 9(4).

77 SOLVE_QUOTIENT PIC 9(4).

PROCEDURE DIVISION.

PARA.

DISPLAY "MATH CALCULATOR IN COBOL".

DISPLAY "".

DISPLAY "ENTER THE FIRST VALUE : ".

ACCEPT NUM_1.

DISPLAY "ENTER THE SECOND VALUE : ".

ACCEPT NUM_2.

COMPUTE SOLVE_SUM = NUM_1 + NUM_2.

COMPUTE SOLVE_DIFF = NUM_1 - NUM_2.

COMPUTE SOLVE_PRODUCT = NUM_1 * NUM_2.

COMPUTE SOLVE_QUOTIENT = NUM_1 / NUM_2.

DISPLAY "".

DISPLAY "===== DISPLAY RESULT =====".

DISPLAY "".

DISPLAY "THE SUM IS ".

DISPLAY SOLVE_SUM.

DISPLAY "".

DISPLAY "THE DIFFERENCE IS ".

DISPLAY SOLVE_DIFF.

DISPLAY "".

DISPLAY "THE PRODUCT IS ".

DISPLAY SOLVE_PRODUCT.

DISPLAY "".

DISPLAY "THE QUOTIENT IS ".

DISPLAY SOLVE_QUOTIENT.

STOP RUN.



2 comments: