Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question about COBOL. I have the following program: IDENTIFICATION DIVISION. PRO

ID: 3880519 • Letter: Q

Question

Question about COBOL. I have the following program:

IDENTIFICATION DIVISION.
       PROGRAM-ID. Multiplier.
       AUTHOR. James P Lucas
       DATE-WRITTEN. Jan 31, 2018
      * Example program using ACCEPT, DISPLAY and MULTIPLY to
      * get two single digit numbers from the user and multiply them
      * together
       ENVIRONMENT DIVISION.

       DATA DIVISION.

       WORKING-STORAGE SECTION.
       01 Num1                                PIC 9 VALUE ZEROS.
       01 Num2                                PIC 9 VALUE ZEROS.
       01 Num3                                PIC 99 VALUE ZEROS.
       01 Num4                                pic 99 value zeros.
       01 Num5                                pic 99 value zeros.
       01 Result                              PIC 999 VALUE ZEROS.

       PROCEDURE DIVISION.
       DISPLAY "Enter first number (1 digit) : " WITH NO ADVANCING.
       ACCEPT Num1.
      
       DISPLAY "Enter second number (1 digit) : " WITH NO ADVANCING.
       ACCEPT Num2.
      
       DISPLAY "Enter third number (1 digit) : " WITH NO ADVANCING.
       ACCEPT Num3.
      
       DISPLAY "Enter fourth number (1 digit) : " WITH NO ADVANCING.
       ACCEPT Num4.
      
       DISPLAY "Enter fifth number (1 digit) : " WITH NO ADVANCING.
       ACCEPT Num5.
      
       MULTIPLY Num1 by num2 by Num3 by Num4 By Num5 giving Result.
      
       DISPLAY "Result is = ", Result.
      
       ADD Num1, num2, num3, num4, num5 giving Result.
      
       DIVIDE Result by 5 giving Result.
      
       DISPLAY "Average is = ", Result.
      
       STOP RUN.

I am trying to get it to compile 5 numbers instead of just 2, and the instructions are as follows:

·       Prompt for 3 more numbers (all integers – picture clause of 99)

·       Calculate the average of all five numbers.

·       Print your name and date

·       Print the five numbers and the average

Hints:

·       You will need to create working storage variables which are integer. The numbers to be read in will have 2 digits (picture clause of 99). The addition of the 5 numbers will need a picture clause of 999. (3 digits)

·       To add you would use the following syntax:

ADD value1 value2 value3 value4 value5 giving total.

·       To divide, you would use the following syntax:

DIVIDE total by 5 GIVING average.

Explanation / Answer

IDENTIFICATION DIVISION.
       PROGRAM-ID. Multiplier.
       AUTHOR. James P Lucas
       DATE-WRITTEN. Jan 31, 2018
      * Example program using ACCEPT, DISPLAY and MULTIPLY to
      * get two single digit numbers from the user and multiply them
      * together
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 Num1                                PIC 99 VALUE ZEROS.
       01 Num2                                PIC 99 VALUE ZEROS.
       01 Num3                                PIC 99 VALUE ZEROS.
       01 Num4                                pic 99 value zeros.
       01 Num5                                pic 99 value zeros.
       01 Result                              PIC 999 VALUE ZEROS.
       PROCEDURE DIVISION.
       DISPLAY "Enter first number (1 digit) : "
       ACCEPT Num1.
     
       DISPLAY "Enter second number (1 digit) : "
       ACCEPT Num2.
     
       DISPLAY "Enter third number (1 digit) : "
       ACCEPT Num3.
     
       DISPLAY "Enter fourth number (1 digit) : "
       ACCEPT Num4.
     
       DISPLAY "Enter fifth number (1 digit) : "
       ACCEPT Num5.
     
     
       ADD Num1 Num2 Num3 Num4 Num5 giving Result.
      
     
       DIVIDE Result by 5 giving Result.
     
       DISPLAY "Average is = ", Result.
     
       STOP RUN.

Output:

Enter first number (1 digit) :4
Enter second number (1 digit) :6
Enter third number (1 digit) :7
Enter fourth number (1 digit) :8
Enter fifth number (1 digit) :2
Average is = 005

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote