% interest_sequence.m
%
%  Compute the sequence of values corresponding to the amount in a bank
%  account at an annual interest rate of r, starting at $1000 in 2017.
%
rate = input ( 'Enter interest rate as a decimal, such as 0.04: ' );
initial_year = 2017;
initial_value = 1000.0;
final_year = input ( 'Enter the year after 2017 when we will stop: ' );

fprintf ( '\n' );
fprintf ( 'Year  Amount\n' );
fprintf ( '\n' );

for year = initial_year : final_year
  value = initial_value * ( 1.0 + rate ) ^ ( year - initial_year );
  fprintf ( '%d: $%.2f\n', year, value );
end

