Suppose you are collecting money for something. You need ₹ 200 in all. You ask your parents, uncles and aunts as well as grandparents. Different people may give either ₹ 10, ₹ 20 or even ₹ 50. You will collect till the total becomes 200. Write the algorithm.
Algorithm to Collect Money Until Total Reaches ₹200
Step 1: SET total = 0
Step 2: WHILE total < 200, REPEAT steps 3 to 4
Step 3: INPUT amount (money given by a person: ₹10, ₹20, or ₹50)
Step 4: total = total + amount
Step 5: PRINT "Collection complete. Total collected: ₹", total
Explanation:
The algorithm begins by initializing the variable 'total' to zero. This variable keeps track of the cumulative money collected from all donors.
A WHILE loop is used to repeatedly accept money from different people (parents, uncles, aunts, grandparents) until the total reaches ₹200. The loop condition 'total < 200' ensures that collection continues as long as the amount is less than the target.
Inside the loop, the algorithm accepts an INPUT for the amount given by each person. As per the problem, this amount can be ₹10, ₹20, or ₹50. The algorithm then adds this amount to the running total.
Once the loop terminates (when total becomes 200 or more), the algorithm displays a message indicating that the collection is complete along with the total amount collected.
This is an example of an iterative algorithm where a set of steps repeats for a finite number of times until a specific condition is met.
Explanation
This question tests the student's understanding of iterative algorithms using loops. The textbook context (Example 4.8) demonstrates a similar pattern using a WHILE loop with a counter and sum. Here, instead of counting iterations, we use a condition based on the total amount collected. The algorithm follows the standard structure: initialization, loop condition, input/process within loop, and final output. Students should recognize this as a sentinel-controlled loop where the termination condition depends on reaching a target value (₹200).
Solution Steps
Step 1: Initialize total to 0
Step 2: Set up WHILE loop with condition total < 200
Step 3: Accept input amount from each person
Step 4: Add amount to total inside the loop
Step 5: Print final total when loop ends