% interest_until.m
%
%  Compute the yearly amount in a bank account at an annual interest rate of 
%  rate, starting at $1000 in 2017, and continuing until we reach at 
%  least TARGET dollars.
%
rate = input ( 'Enter interest rate as a decimal, such as 0.04: ' );
target = input ( 'Enter the target value, greater than 1000: ' );
year = 2017;

while ( true )

  if ( year == 2017 )
    value = 1000.0;
  else 
    value_old = value;
    value = ( 1.0 + rate ) * value_old;
  end

  fprintf ( '%d: $%.2f\n', year, value );

  if ( target <= value )
    break;
  end

  year = year + 1;

end

