## 2.3 Iteration Control Structures

### Assignment 2.3.1 Pseudo code - Iterational pattern (1)

**Objective: Write pseudo code for iterational pattern problems.**

**Problem 1 :**

**The problem given in Assignment 2.1.2 is extended to check whether**

**the Number of Hours accepted from the user is less than or equal to 0. If so display an error**

**message. Reenter the data the Number of Hours until valid data is entered.**

**Step 1: Write the following Pseudo code**

1. input No_of_Hours, Pay_Rate

2. while(------------) do

3. display "---------------------"

4. -------------------------------------

5. end while

6. Gross_Pay = No_of_Hours * Pay_Rate

7. display " The gross pay is equal to : ", Gross_Pay

8. end

**Step 2 : Fill in the missing (------) parts in the Pseudo code**

**We need to put a condition in the parenthesis of while ( ) loop, which could test the validity of the data input by the user for the number of hours. We need to keep the loop running displaying a message as long as the condition in the parenthesis remains true. Therefore the complete form the above pseudocode is given as :**

CALC_GROSS_PAY

1. input No_of_Hours, Pay_Rate

2. while(No_of_Hours < = 0) do

3. display "Invalid Entry, Enter Valid Number of hours. "

4. input No_of_Hours

5. end while

6. Gross_Pay = No_of_Hours * Pay_Rate

7. display " The gross pay is equal to : ", Gross_Pay

8. end

Problem 2 :

**Write a pseudo code to calculate the Loan Balance, where a person**

**borrows an amount A and in return he/she agrees to make N payments per year, each of**

**amount P. While the person is repaying the loan, interest will accumulate at an annual**

**percentage rate of R, and this interest will be compounded N times a year (along with each**

**payment). Therefore, the person must continue paying these installments of amount P until**

**the original amount and any accumulated interest is repaid.**

**NOTE: The formula to calculate the amount that the person needs to repay after T years is :**

**Balance amount after T years =**

## No comments:

## Post a Comment