View previous topic :: View next topic
|
Author |
Message |
JimBrumbaugh
New User
Joined: 05 Nov 2022 Posts: 2 Location: United States
|
|
|
|
Hello everyone, I have chosen to used COBOL to write a quick program for a class I am taking and I have the basic coding down, I have an array that holds 10 numbers and I need to sort them either ascending or descending. I need to use a simple menu that gives the user (teacher) the option to pick which sort he wants. The menu and the sorting is what has me stumped right now. I hope someone can help ASAP. I do appreciate all of your help.
I would also love all advice on how to improve my code.
Here is the code so far:
Code: |
WORKING-STORAGE SECTION.
*> Declare a single digit integer between 0-9
*> with a starting value of 0
*> ZEROS is a constant equal to 0
01 NUMBER-TABLE.
05 NUMBER-PRD OCCURS 10 TIMES PIC X(9).
01 Num0 PIC 9 VALUE ZEROS.
01 counter PIC S999 VALUE 1.
01 MyLoop PIC 99.
*----------------------
PROCEDURE DIVISION.
*----------------------
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
MAIN-PROCEDURE.
**
* The main procedure of the program
**
DISPLAY "############################################### ".
DISPLAY "############################################### ".
DISPLAY "Enter 1st number : ".
ACCEPT NUMBER-PRD(1).
DISPLAY "Enter 2nd number : ".
ACCEPT NUMBER-PRD(2).
DISPLAY "Enter 3rd number : ".
ACCEPT NUMBER-PRD(3).
DISPLAY "Enter 4th number : ".
ACCEPT NUMBER-PRD(4).
DISPLAY "Enter 5th number : ".
ACCEPT NUMBER-PRD(5).
DISPLAY "Enter 6th number : ".
ACCEPT NUMBER-PRD(6).
DISPLAY "Enter 7th number : ".
ACCEPT NUMBER-PRD(7).
DISPLAY "Enter 8th number : ".
ACCEPT NUMBER-PRD(8).
DISPLAY "Enter 9th number : ".
ACCEPT NUMBER-PRD(9).
DISPLAY "Enter 10th number : ".
ACCEPT NUMBER-PRD(10).
DISPLAY "HERE ARE YOUR NUMBERS: ".
DISPLAY" NUMBER 1: " NUMBER-PRD(1).
DISPLAY" NUMBER 2: " NUMBER-PRD(2).
DISPLAY" NUMBER 3: " NUMBER-PRD(3).
DISPLAY" NUMBER 4: " NUMBER-PRD(4).
DISPLAY" NUMBER 5: " NUMBER-PRD(5).
DISPLAY" NUMBER 6: " NUMBER-PRD(6).
DISPLAY" NUMBER 7: " NUMBER-PRD(7).
DISPLAY" NUMBER 8: " NUMBER-PRD(8).
DISPLAY" NUMBER 9: " NUMBER-PRD(9).
DISPLAY" NUMBER 10: " NUMBER-PRD(10).
STOP RUN.
|
Thank you,
Jim |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
Before COBOL, you strongly need to find and to learn the SORT algorithm.
There are plenty of them. Use Google Search on “sort algorithm” |
|
Back to top |
|
|
JimBrumbaugh
New User
Joined: 05 Nov 2022 Posts: 2 Location: United States
|
|
|
|
sergeyken wrote: |
Before COBOL, you strongly need to find and to learn the SORT algorithm.
There are plenty of them. Use Google Search on “sort algorithm” |
Thank you sir for the input and I agree it would be a great idea to understand the sorting algorithm prior to trying this but I do not have a few weeks to figure this out, I need to turn in the work tomorrow. So just a few pointers ot tips would be a huge help
Jim |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
JimBrumbaugh wrote: |
sergeyken wrote: |
Before COBOL, you strongly need to find and to learn the SORT algorithm.
There are plenty of them. Use Google Search on “sort algorithm” |
Thank you sir for the input and I agree it would be a great idea to understand the sorting algorithm prior to trying this but I do not have a few weeks to figure this out, I need to turn in the work tomorrow. So just a few pointers ot tips would be a huge help
Jim |
It took me about 10 seconds to find an almost ready-to-use solution:
CODING COBOL: A BUBBLESORT
I will never adjust it to your specific variable names etc.
If you are not able to do it by yourself, then I strongly recommend you to change your job. Seriously. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
FYI for the non students: IBM Enterprise COBOL now has built in support for sorting tables defined in the Data Division. The SORT verb accepts a table as input. |
|
Back to top |
|
|
|