Ask Question

The for loop calculates the amount of money in a savings account after numberYears given an initial balance of savingsBalance and an annual interest rate of 2.5%.

Complete the for loop to iterate from 1 to numberYears (inclusive).

function savingsBalance = CalculateBalance (numberYears, savingsBalance)

% numberYears: Number of years that interest is applied to savings

% savingsBalance: Initial savings in dollars

interestRate = 0.025; % 2.5 percent annual interest rate

% Complete the for loop to iterate from 1 to numberYears (inclusive)

for ()

savingsBalance = savingsBalance + (savingsBalance * interestRate);

end

end

+2
Answers (1)
  1. 4 October, 21:28
    0
    function savingsBalance = CalculateBalance (numberYears, savingsBalance) % numberYears: Number of years that interest is applied to savings % savingsBalance: Initial savings in dollars interestRate = 0.025; % 2.5 percent annual interest rate % Complete the for loop to iterate from 1 to numberYears (inclusive) for n = 1:numberYears savingsBalance = savingsBalance + (savingsBalance * interestRate); end end

    Explanation:

    The solution code is written in Matlab.

    To complete the for loop, we just need to set the range of the years to enable the for loop to traverse through. We add expression 1:numberYears to enable the loop to iterate from 1 to numberYears. For example, if the input numberYears is 10, the for loop will run for 10 times by traversing the number from 1 to 10 (inclusive) and accumulating the savingsBalance for 10 years. The loop will stop after 10 rounds of iterations.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “The for loop calculates the amount of money in a savings account after numberYears given an initial balance of savingsBalance and an annual ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers