Ask Question
9 February, 20:50

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. 9 February, 23:42
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers