cobol calculator



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

cobol calculator

Postby ajit mainframe » Mon Oct 25, 2010 10:03 am

hi,i am trying to build a calculator in cobol. It compiled succesfully and ran also. but when i am trying to get output by supplying sysin parameters it is showing all variable output as 00000.can you please review and give comments for correction. Thanks.

000100 IDENTIFICATION DIVISION.                                         00010000
000200 PROGRAM-ID. CALC.                                                00020000
000300 ENVIRONMENT DIVISION.                                            00030000
000400 DATA DIVISION.                                                   00040001
000500 WORKING-STORAGE SECTION.                                         00050003
000600   01 A         PIC 9(2) VALUE 6.                                 00060006
000700   01 B         PIC 9(2) VALUE 2.                                 00070006
000800   01 RESULT    PIC 9(5) VALUE ZEROS.                             00080006
000810   01 KEYPRESS  PIC X.                                            00081002
000900 PROCEDURE DIVISION.                                              00090002
000901       ACCEPT A FROM SYSIN                                        00090106
000902       ACCEPT KEYPRESS FROM SYSIN                                 00090206
000903       ACCEPT B FROM SYSIN                                        00090306
000910       IF KEYPRESS = "+" THEN                                     00091002
001000       COMPUTE RESULT = A + B.                                    00100002
001100       DISPLAY 'SUMMATION IS ' RESULT.                            00110012
001110       IF KEYPRESS = "-" THEN                                     00111002
001200       COMPUTE RESULT = A - B.                                    00120002
001300       DISPLAY 'SUBSTRACTION IS ' RESULT.                         00130012
001310       IF KEYPRESS = "*" THEN                                     00131002
001400       COMPUTE RESULT = A * B.                                    00140002
001500       DISPLAY 'MULTIPLICATION IS ' RESULT.                       00150012
001510       IF KEYPRESS = "/" THEN                                     00151002
001600       COMPUTE RESULT = A / B.                                    00160002
001700       DISPLAY 'DIVISION IS ' RESULT.                             00170012
001710       IF KEYPRESS = "%" THEN                                     00171010
001800       COMPUTE RESULT = FUNCTION MOD(A, B).                       00180010
001900       DISPLAY 'MODULUS IS ' RESULT.                              00190012
002000       STOP RUN.                                                  00200002
ajit mainframe
 
Posts: 5
Joined: Mon Oct 25, 2010 9:55 am
Has thanked: 0 time
Been thanked: 0 time

Re: cobol calculator

 

Re: cobol calculator

Postby dick scherrer » Mon Oct 25, 2010 10:32 am

Hello and welcome to the forum,

Suggest you define some decimal places in RESULT.

You need to post the jcl used to run this also.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: cobol calculator

Postby Robert Sample » Wed Oct 27, 2010 5:33 pm

Is your COBOL compiler using APOST or QUOTE?

Furthermore, as coded you are going to seeing RESULT printed 5 times -- potentially 4 times as zero, guaranteed and up to 5 copies of the same number with different labels -- even though you only do one calculation.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post