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

Consider the following equation to compute future value often used for basic fin

ID: 671052 • Letter: C

Question

Consider the following equation to compute future value often used for basic financial calculations: fv= m n=o D(1+r)n where FV = future value D = monthly or yearly deposit r = monthly or yearly interest rate (e.g. a 5% implies r = 5/100). M = final number of months or years Write a script that will prompt the user for FV, M (in months or years), and r and computes the required monthly or yearly deposit D. Sample output: Welcome to your future value calculator. Please enter a desired future value in dollars: 1000000 Do you want to work in monthly (m) or yearly (y) rates? m Please enter the number of months you will be making deposits: 480 Please enter the monthly interest rate as a percentage: 5/12 To reach 1000000 dollars in 480 months your monthly deposit should be 652.1547

Explanation / Answer

disp("Welcome to your future value calculator");

fv = sscanf(input('Please enter a desired future value in dollars', 's'), '%f');
%fv = 1000000;

%monthly or yearly
mOrY = sscanf(input('Do you want to work in monthly(m) or yearly (y) rates ', 's'), '%s');

%mOrY = "y";

msgStr = "Please enter number of moths you will be making deposits ";

if(mOrY == "y" || mOrY == "Y")
msgStr = "Please enter number of years you will be making deposits ";
end

nMonths= sscanf(input(msgStr, 's'), '%d');

%nMonths = 480;

%monthly interest rate
msgStr = "Please enter the monthly interest rate as a percentage";
if(mOrY == "y" || mOrY == "Y")
msgStr = "Please enter the yearly interest rate as a percentage ";
end
disp(msgStr);
mInterestRate = sscanf(input(msgStr, 's'), '%f');
%interestRate = 5/12;

M = nMonths;
r = interestRate /100;

deposit = 0;
%FV = sigma[0,M] [D * (1+r)^n] = D * sigma[0,M] [ (1+r)^n]

interestSeriesSum = 0;
for n =0 : M
interestSeriesSum= interestSeriesSum + power(1+r,n);

end


%D = FV/(sigma[0,M] [ (1+r)^n] )
deposit = fv/interestSeriesSum;

msgStr ="monthly";
if(mOrY == "y" || mOrY == "Y")
msgStr = "yearly ";
end

fprintf("To reach %f dollars in %d months your %s deposit should be %f",fv,nMonths,msgStr, deposit);