000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.   PRMCHKRB.
000300 AUTHOR.       Ryan Brooks.
000400* CONVERT THE IN-LINE PERFORMS INTO PARAGRAPHS.
000500 DATE-WRITTEN. MAR 2017 
000600 DATA DIVISION. 
000700 WORKING-STORAGE SECTION.
000800
000900 01 NUM-IN          PIC XXXX.
001000    88 INTEGER-ENTERED       VALUE "0000" THRU "9999".
001100    88 USER-WANTS-TO-QUIT    VALUE "x" "X" "XX" "xx".
001200 01 NUM-IN-INT REDEFINES
001300    NUM-IN          PIC 9999.
001400 01 WS-QUOTIENT     PIC 9999 VALUE 0.
001500 01 WS-REMAINDER    PIC 9999 VALUE 1.
001600    88 NOT-PRIME-NUMBER      VALUE 0.
001700 01 WS-DIVISOR      PIC 9999 VALUE 0.
001800  
001900 PROCEDURE DIVISION.
002000 0000-DRIVER.
002100     DISPLAY "Prime Number Checking Program".
002200     PERFORM 1100-GET-USER-INPUT.
002300     PERFORM 1000-CHECK-NUMBER
002400       UNTIL USER-WANTS-TO-QUIT.
002500     display "EXIT".
002600     GOBACK.
002700     
002800 1000-CHECK-NUMBER.
002900* CHANGE THE IN-LINE PERFORM TO A PARAGRAPH, 1010-DIVISION-CALC
003000  PERFORM 1010-DIVISION-CALC
003100     
003200* CHANGE THIS NUMBER CHECK TO A PARAGRAPH YOU ADD, 1020-PRIME-CHK
003300* THIS WILL MEAN CREATING A PARAGRAPH WITH THE IF STATEMENT, 
003400* REMOVING THESE LINES OF CODE AND REFERENCING THE NEW PARA. 
003500     PERFORM 1020-PRIME-CHK.
003600     PERFORM 1100-GET-USER-INPUT.
003700     
003800 1010-DIVISION-CALC.
003900* PUT THE CODE FROM THE IN-LINE PERFORM HERE.
004000    add 1 to WS-REMAINDER
004100    PERFORM VARYING WS-DIVISOR FROM 2 BY 1 
004200       UNTIL WS-REMAINDER = 0
004300          OR WS-DIVISOR = (NUM-IN-INT - 1)
004400         DIVIDE NUM-IN-INT by WS-DIVISOR 
004500           GIVING WS-REMAINDER REMAINDER WS-REMAINDER
004600     END-PERFORM.
004700 
004800 1020-PRIME-CHK.
004900     IF NOT-PRIME-NUMBER
005000       DISPLAY NUM-IN " IS NOT A PRIME"
005100     ELSE  
005200       display NUM-IN " IS A PRIME".
005300     MOVE SPACES TO NUM-IN.
005400     
005500 1100-GET-USER-INPUT.
005600* CHANGE THIS IN-LINE PERFORM TO EXECUTE IN A NEW PARAGRAPH
005700* NAMED 1110-INPUT-CHECK.  ADD THIS PARAGRAPH, MOVE THE CODE
005800* TO IT AND REFERENCE IT.
005900  
006000     PERFORM until NUM-IN is numeric OR USER-WANTS-TO-QUIT
006100       display "ENTER INTEGER 0000-9999 (WITH LEADING ZEROES)"
006200       display "(OR ENTER X TO QUIT)."
006300       ACCEPT NUM-IN
006400     END-PERFORM