Master Mainframe Technologies - COBOL, JCL, DB2, VSAM, CICS & More
ABEND Codes SQLCODEs File Status Interview Prep Contact
← Back to Arithmetic Operations
Arithmetic Operations | Intermediate | COBOL

Simple Interest Calculator

Problem Description

Calculate simple interest: SI = (P * R * T) / 100

Expected Output

Principal=1000, Rate=5, Time=2 -> Interest=100

Hints

Define variables with proper decimal places for currency.

Solution

IDENTIFICATION DIVISION. PROGRAM-ID. SIMPLEINT. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-PRINCIPAL PIC 9(7)V99. 01 WS-RATE PIC 9(2)V99. 01 WS-TIME PIC 9(2). 01 WS-INTEREST PIC 9(7)V99. PROCEDURE DIVISION. DISPLAY "ENTER PRINCIPAL: ". ACCEPT WS-PRINCIPAL. DISPLAY "ENTER RATE: ". ACCEPT WS-RATE. DISPLAY "ENTER TIME: ". ACCEPT WS-TIME. COMPUTE WS-INTEREST = (WS-PRINCIPAL * WS-RATE * WS-TIME) / 100. DISPLAY "SIMPLE INTEREST: " WS-INTEREST. STOP RUN.

Explanation:

V99 gives 2 decimal places for currency.