006-003-007

While Loop: Goal Achievement

Medium

Problem Description

while loop: Goal Achievement

In this problem, you will create a program that reads a monthly savings amount and a goal amount, uses a while loop to calculate and display the cumulative savings for each month until the goal is reached, and outputs the total number of months required.

Learning Objective: Write processing that repeats until a condition is met using while loops

Create a simulation program that continues saving monthly until reaching a goal amount. Use while loops for conditional repetition.

Input

Line 1: Monthly savings (integer)
Line 2: Goal amount (integer)

Output

Display cumulative savings each month, then show how many months it took

Examples

Example 1

Input:

1000
3000

Output:

Month 1: 1000
Month 2: 2000
Month 3: 3000
Goal reached in 3 months!

Example 2

Input:

500
1500

Output:

Month 1: 500
Month 2: 1000
Month 3: 1500
Goal reached in 3 months!

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up