Ask Question
25 August, 14:05

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

+3
Answers (1)
  1. 25 August, 14:11
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers