Sectionย 1. Chapterย 41
single
Challenge: do-while Loop
Swipe to show menu
Task
Swipe to start coding
In this task, you will practice using a do-while loop to simulate a real-life scenario: saving money daily until reaching a target amount.
- Inside the
CalculateSavingsmethod:- Initialize
totalSavedto0. - Initialize
daysto0. - Use a do-while loop to:
- Add
dailySavingtototalSavedeach day. - Increment
daysby 1. - Repeat the loop until
totalSavedis greater than or equal totargetAmount.
- Add
- Initialize
Solution
Everything was clear?
Thanks for your feedback!
Sectionย 1. Chapterย 41
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat