Question #54762

Suppose you have a certain amount of money in a savings account that earns compound interest, and you want to calculate the amount that you will have after a specific number of months. The formula is as follows:
F = P X (1 + i) ^ t
The terms in the formula are:
F is the future value of the account after the account after the specified time period.
P is the present value of the account.
i is the monthly interest rate.
t is the number of months.
Write a program that executes a loop 5 times. Each step of the loop generate a random value for P, i (between 0 and 10 percent) , and the number of months betwen (1 and 100). The loop should then pass these values to a function that returns the future value of the account, after the specified number of months. The program should display the accounts future value each pass. See sample output below:
Present Value: $500.00
Monthly Interest Rate: .07
Number of Months: 72
Future Value: $65,253.23
1

Expert's answer

2015-09-19T00:00:43-0400

Answer on Question #54762 - Programming - AJAX | JavaScript | HTML | PHP

Program contents:


function returnFutureValue(p, i, t) {
    return p * Math.pow((1 + i), t);
}
for(var c=0; c<5; c++) {
    var p = parseInt(Math.floor(Math.random() * 1000) + 1); // get random value of the present value of account
    var i = (parseInt(Math.floor(Math.random() * 10))/10); // get random value of the monthly interest rate
    var t = parseInt(Math.floor(Math.random() * 100) + 1); // get random the number of months
    var f = returnFutureValue(p, i, t);
}
var result = 'Present Value: $' + p.toString() + "\r\n"
    + 'Monthly Interest Rate: ' + i.toString() + "\r\n"
    + 'Number of Months: ' + t + "\r\n"
    + 'Future Value: $' + f.toFixed(2).toString() + "\r\n";
console.log(result); //show results
}


http://www.AssignmentExpert.com/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS