Здравейте!
Запънах се на една задачка и се чудя какво бъркам. Кода ми върви, но може би съм объркал нещо с математиката?
Задачата е следната:
Interest
You have deposited a sum into your bank account for 3 years. The bank has announced an interest of 5% per year. Each time the interest is calculated and added to your deposit. You have to calculate the amount in your deposit for each year.
Input
- On the only line you will receive a number (n) with the sum deposited
Output
- You should print the amount in your deposit for each of the 3 years
Constraints
- You must print the number with two numbers after the decimal point. The rules of math for rounding apply here
Моето решение:
let sumDep = +gets();
let yearOne = sumDep * 0.05;
let yearTwo = yearOne * 0.05 + yearOne;
let yearThree = yearTwo * 0.05 + yearTwo;
print(yearOne.toFixed(2)+ “\n”+ yearTwo.toFixed(2)+"\n" +yearThree.toFixed(2));
Благодаря предварително!