68.9k views
4 votes
Provide an example of calculating yearly savings using a for loop.

User Pssguy
by
8.9k points

1 Answer

4 votes

Final answer:

To calculate yearly savings using a for loop, you can use the simple interest formula.

Step-by-step explanation:

To calculate yearly savings using a for loop, you can use the simple interest formula. Let's assume you are saving $100 each year and the interest rate is 5%. Here's an example:

Step 1: Set the initial savings amount to 0.

Step 2: Use a for loop to iterate over each year.

Step 3: Inside the for loop, calculate the interest earned for that year and add it to the savings amount.

Step 4: After the for loop ends, you will have the total savings amount for the specified number of years.

In this example, after 3 years, the total savings amount can be calculated as:

$100 * 0.05 * 1 + $100 * 0.05 * 2 + $100 * 0.05 * 3 = $15

User NOlivNeto
by
8.6k points