function investmentValue(startingIncome, annualRaise, percentInvested, interestRate, yearsInvested)
{
	if (yearsInvested <= 0)
	{
		return percentInvested*startingIncome;
	}
	
	return ((investmentValue(startingIncome, annualRaise, percentInvested, interestRate, yearsInvested-1) + (incomeLastYear(startingIncome, annualRaise,yearsInvested) * percentInvested)) * (1+interestRate));
		


}

function moneyEarned(startingIncome, annualRaise,yearsInvested)
{
	var totalMoney = 0;
	var curYearIncome = startingIncome;
	for (var i=0; i<yearsInvested; i++)
	{
		totalMoney += curYearIncome;
		curYearIncome *= (1 + annualRaise);
	}
	
	return totalMoney;


}

function incomeLastYear(startingIncome, annualRaise,yearsInvested)
{
	var curYearIncome = startingIncome;
	for (var i=0; i<yearsInvested; i++)
	{
		curYearIncome *= (1 + annualRaise);
	}
	
	return curYearIncome;


}


function moneySaved(startingIncome, annualRaise, percentageInvested, yearsInvested)
{
	var totalMoney = 0;
	var curYearIncome = startingIncome;
	for (var i=0; i<yearsInvested; i++)
	{
		totalMoney += curYearIncome * percentageInvested;
		curYearIncome *= (1 + annualRaise);
	}
	
	return totalMoney;


}

function solve(form){

 form.investmentValue.value = investmentValue(parseFloat(form.sI.value), parseFloat(form.aR.value), parseFloat(form.pI.value), parseFloat(form.iR.value), parseInt(form.yI.value));
 form.moneyEarned.value = moneyEarned(parseFloat(form.sI.value), parseFloat(form.aR.value), parseInt(form.yI.value));
 form.moneySaved.value = moneySaved(parseFloat(form.sI.value), parseFloat(form.aR.value), parseFloat(form.pI.value), parseInt(form.yI.value));
 form.incomeLastYear.value =  incomeLastYear(parseFloat(form.sI.value), parseFloat(form.aR.value), parseInt(form.yI.value));
 form.returnLastYear.value = parseFloat(form.investmentValue.value) * parseFloat(form.iR.value);
 form.difference.value = parseFloat(form.returnLastYear.value) - parseFloat(form.incomeLastYear.value);
}
