# MATLAB: Future Bank Account Balance

homeworkwhile loop

I have to create a while loop that will calculate how much money will be in my bank account 18 years from now. I start off with \$2000, the interest is 0.4%, and my contribution to the account each month is \$150. I have to use a while loop to do this and have a plot to show its increase over time. This is what I have but can't seem to make it work:
``oldbalance = 2000;contribution = 150;while i <= 216    interest = 0.4/100*oldbalance;    newbalance(i) = oldbalance(i) + interest(i) + contribution(i);    oldbalance = newbalance(i);endplot(1:1:216,newbalance(i))xlabel('time,(months)');ylabel('amount in the account in dollars');title('Plot of amount in the account as a function of time');``

``oldbalance = newbalance(i);``
``balance = 2000;contribution = 150;i = 1; % you need to initialize iwhile i < 216    interest = 0.4/100*balance(i);    balance(i+1) = balance(i) + interest + contribution; % assumes contribution goes in at the end of the period.    i = i + 1; % you need to increment iend``