I am trying to see how many years it will take for me to save a million dollars using the following conditions: monthlyWageAfterTaxes = 2700; numberOfYears=30;
Expenses.... rent=800; utilities=300; insurance=200; auto=250; food_misc=325; My rent increases $200 every five years,first time in month 61 and my monthlyWageAfterTaxes increases 2% every year,first time in month 13.
Here is my code so far:
% input statements
monthlyWageAfterTaxes = 2700;
savingsGoal= input('Type in a savings goal: ');
while totalSavings < savingsGoal
if rem(numYears,5) ==0;
rent = rent + 200;
totalSavings = totalSavings + monthlyWageAfterTaxes*12 - monthlyBills*12
monthlyWageAfterTaxes = monthlyWageAfterTaxes * 1.02;
My problem is that I want to show the number of years as a decimal instead of the code rounding to the nearest whole year. I worked it out on paper and I get 48.16667 years but when I run the code, the answer is 51 years. Can anyone see what my error is? I am trying to solve this problem by just using years, but do I need to solve using months and then divide by 12 at the end of the code?
1 Replies - 977 Views - Last Post: 02 November 2012 - 04:25 AM
Replies To: Answer should be a decimal, not rounded to whole number in while loop
Re: Answer should be a decimal, not rounded to whole number in while loop
Posted 02 November 2012 - 04:25 AM
When asking a question in the Other Languages forum, you should mention which language you're talking about - preferably in the title.
Page 1 of 1