A person wants to save for a trip which will cost $12000 , initial deposit $4000 invested at interest of 5.8% per annum and plan to deposit $400 every month,
1)write a code which uses a loop statement to determine how many months are required for the savings to exceed $12000
2)Amount=Amount(1+(rate/1200))+400 using this code get it to display the number of months required and the total amount saved
1)is this right dep = 400; amount = 4000; year = 0; while account = 12000 amount = amount(1+((0.058/1200)) + 400; end
2) dont understand
No products are associated with this question.
The first thing that is not correct is the condition in the WHILE statement; you want to repeat the loop while the amount is below 12,000. Written with the equality, the program will never enter the loop as the condition is wrong initially.
You can test your computation by removing the ";" that you put at the end of the line that updates the variable amount, so the value is displayed at each step of the iteration. If you compute a few values by hand, you'll be able to compare. Note that
(which is a copy of the expression in the second part of the question) is not a valid MATLAB expression for what you want to do, as it would be an indexing operation on amount.