View previous topic :: View next topic
|
Author |
Message |
rajaseelan j
New User
Joined: 05 Apr 2012 Posts: 1 Location: India
|
|
|
|
How to add 5 numbers in cobol with input 1,2,3,4,5 in the same line?
Reading input delimited by comma in same line in cobol so that input is like
For EX:
Input: 1,2,3,4,5 using keyboard
And the output should come as 15 |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you browse the Cobol forum where you have posted you'll see some relevant topics.
Look at things like UNSTRING, STRING, INSPECT and NUMVAL in the Cobol manuals (link at the top of the page). |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
OK, I assume you've done all that now.
Can be tricky and is error-prone.
Go back to the spec-writer and see if you can get this done.
"Pre-process" your input file with your SORT product. Use PARSE to put the fields into fixed positions of fixed length. In your program, check that each is numeric, rejecting appropriately if not, then add them all up in the normal way. It'll make things easier all around, especially if the input file is used in more than one place. |
|
Back to top |
|
|
|