Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The for loop calculates the amount of money in a savings account after numberYea

ID: 3928322 • Letter: T

Question

The for loop calculates the amount of money in a savings account after numberYears given an initial balace 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 5 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 Code to call your function when you click Run

Explanation / Answer

function savingsBalance = CalculateBalance(numberYears, savingsBalance)
interestRate = 0.025;
for n = 1:numberYears
savingsBalance = savingsBalance + (savingsBalance*interestRate);
end
end

CalculateBalance(1,1000)

/*

Output

ans =  1025

Explanation

for n = 1:numberYears means it starts from 1 to numberYears(inclusive)

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote