IF statements - pick correct solutions
FD INPUT-FILE
DATA RECORD IS INPUT-REC.
01 INPUT-REC.
05 IDNO PIC XXXXX.
05 NAMZ PIC X(20).
05 SALARY PIC 9(6)V99.
05 DEPT PIC XX.
05 JOB-CLASS PIC X.
05 OVT-CLASS PIC X.
05 HRS-WK PIC 99.
05 OVT-PAYHR PIC 999V99.
Pick the correct solution(s) to the following problems. NOTE: There can be more than
one correct solution.
Problem #1: You want to move OKAY to a message area for all people who have a
salary greater than 50000 and a job classification of either A or B.
Choice A:
IF SALARY > 50000 AND JOB-CLASS = "A" OR JOB-CLASS = "B"
MOVE "OKAY" TO MSG-PR
END-IF
Choice B:
IF SALARY > 50000
IF JOB-CLASS = "A"
MOVE "OKAY" TO MSG-PR
ELSE
IF JOB-CLASS = "B"
MOVE "OKAY" TO MSG-PR
END-IF
END-IF
END-IF
Choice C:
IF SALARY > 50000
IF JOB-CLASS = "A" OR JOB-CLASS = "B"
MOVE "OKAY" TO MSG-PR.
Choice D:
IF SALARY > 50000 AND (JOB-CLASS = "A" OR JOB-CLASS = "B")
MOVE "OKAY" TO MSG-PR.
Choice E:
IF SALARY > 50000
IF JOB-CLASS = "A" OR JOB-CLASS = "b"
MOVE "OKAY" TO MSG-PR.
Problem #2: If the person is eligible for overtime hours (Y in OVT-CLASS), and the
hours worked is greater than 40, you want to multiply the hours worked by the overtime pay
and put it into the salary in working storage and move the salary in working storage to the
print line, if the person is not eligible for overtime hours or if they did not work over
40 hours you want to move their salary to the print line.
Choice A:
IF OVT-CLASS = "Y"
IF HRS-WK > 40
MULTIPLY HRS-WK BY OVT-PAYHR
GIVING SALARY-WS
MOVE SALARY-WS TO SALARY-PR
ELSE
MOVE SALARY TO SALARY-PR
END-IF
ELSE
MOVE SALARY TO SALARY-PR
END-IF
Choice B:
IF OVT-CLASS = "Y" AND HRS-WK > 40
MULTIPLY HRS-WK BY OVT-PAYHR
GIVING SALARY-WS
MOVE SALARY-WS TO SALARY-PR.
ELSE
MOVE SALARY TO SALARY-PR.
Choice C:
IF OVT-CLASS = "Y"
IF HRS-WK > 40
MULTIPLY HRS-WK BY OVT-PAYHR
GIVING SALARY-WS
MOVE SALARY-WS TO SALARY-PR
ELSE
MOVE SALARY TO SALARY-PR
ELSE
MOVE SALARY TO SALARY-PR.
Choice D:
IF OVT-CLASS = "Y" AND HRS-WK > 40
MULTIPLY HRS-WK BY OVT-PAYHR
GIVING SALARY-WS
MOVE SALARY-WS TO SALARY-PR
ELSE
MOVE SALARY TO SALARY-PR
END-IF
Problem #3:If the person is eligible for overtime hours (Y in OVT-CLASS), and the
hours worked is greater than 40, you want to multiply the hours worked by the overtime pay
and put it in the salary in working storage and move the salary in working storage to the
print line along with the message OVERTIME, if the person is not eligible for overtime
hours you want to move their salary to the print line along with the message NOT ELIGIBLE
or if they did not work over 40 hours you want to move their salary to the print line along
with the message NOT OVER 40.
Choice A:
IF OVT-CLASS = "Y" AND HRS-WK > 40
MULTIPLY HRS-WK BY OVT-PAYHR
GIVING SALARY-WS
MOVE "OVERTIME" TO MSG-PR
ELSE
MOVE "NOT ELIGIBLE" TO MSG-PR
END-IF
Choice B:
IF OVT-CLASS = "Y"
IF HRS-WK > 40
MULTIPLY HRS-WK BY OVT-PAYHR
GIVING SALARY-WS
MOVE SALARY-WS TO SALARY-PR
MOVE "OVERTIME" TO MSG-PR
ELSE
MOVE SALARY TO SALARY-PR
MOVE "NOT OVER 40" TO MSG-PR
END-IF
ELSE
MOVE SALARY TO SALARY-PR
MOVE "NOT ELIGIBLE" TO MSG-PR
END-IF
Choice C:
IF OVT-CLASS = "Y"
IF HRS-WK NOT > 40
MOVE SALARY TO SALARY-PR
MOVE "NOT OVER 40" TO MSG-PR
ELSE
MULTIPLY HRS-WK BY OVT-PAYHR
GIVING SALARY-WS
MOVE SALARY-WS TO SALARY-PR
MOVE "OVERTIME" TO MSG-PR
ELSE
MOVE SALARY TO SALARY-PR
MOVE "NOT ELIGIBLE" TO MSG-PR.