Suppose you are collecting money for something. You need Rs. 200 in all. You ask your parents, uncles and aunts as well as grandparents. Different people may give either Rs. 10 , Rs. 20 or even Rs. 50 . You will collect till the total becomes 200. Write the algorithm.
Question
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.
✨ Free AI Tools for You
Powered by Chatterbot AI
Answer
Here is the algorithm to collect money until the total reaches ₹200:
Algorithm to Collect ₹200
Initialize total to 0.
total = 0
While total is less than 200, repeat steps 3 to 5:
WHILE total < 200 REPEAT
Ask for money contribution:
INPUT contribution
Check if contribution is ₹10, ₹20, or ₹50:
IF contribution == 10 OR contribution == 20 OR contribution == 50 THEN
Add the contribution to total:
total = total + contribution
End the loop.
END WHILE
Print the total amount collected:
PRINT total
Pseudocode:
total = 0
WHILE total < 200 REPEAT
INPUT contribution
IF contribution == 10 OR contribution == 20 OR contribution == 50 THEN
total = total + contribution
END IF
END WHILE
PRINT total
Explanation:
Initialize: Start by setting the
total
amount collected to 0.Loop: Keep asking for contributions in a loop until the
total
collected is at least ₹200.Input: Get the contribution amount from a family member.
Condition: Verify if the contribution is one of the valid amounts ₹10, ₹20, or ₹50.
Update: Add the contribution to the
total
collected.End: Exit the loop once the total reaches or exceeds ₹200 and print the total amount collected.
India's 1st AI Doubt Solver for CBSE, JEE, and NEET
Ask a Question for Freeand then it's just ₹212 a month