In this exercise, you'll be working with savings accounts. Each year, the balance of your savings account is updated based on its interest rate. The interest rate your bank gives you depends on the amount of money in your account (its balance):
0 dollars (balance gets more negative).0 dollars, and less than 1000 dollars.1000 dollars, and less than 5000 dollars.5000 dollars.You have four tasks, each of which will deal with the balance and its interest rate.
Implement the interest_rate function to calculate the interest rate based on the specified balance:
interest_rate(200.75);
// => 0.5Implement the yearly_interest function to calculate the interest based on the specified balance:
yearly_interest(200.75):
// => 1.003750Implement the annual_balance_update function to calculate the annual balance update, taking into account the interest rate:
annual_balance_update(200.75);
// => 201.75375Implement the years_until_desired_balance function to calculate the minimum number of years required to reach the desired balance, taking into account that each year, interest is added to the balance.
This means that the balance after one year is: start balance + interest for start balance.
The balance after the second year is the balance after one year + interest for the balance after one year.
And so on, until the current year's balance is greater than or equal to the target balance.
double balance {200.75};
double targetBalance {214.88};
years_until_desired_balance(balance, targetBalance)
// => 14Note that the value returned is an int.
In this exercise, you'll be working with savings accounts. Each year, the balance of your savings account is updated based on its interest rate. The interest rate your bank gives you depends on the amount of money in your account (its balance):
0 dollars (balance gets more negative).0 dollars, and less than 1000 dollars.1000 dollars, and less than 5000 dollars.5000 dollars.You have four tasks, each of which will deal with the balance and its interest rate.
Implement the interest_rate function to calculate the interest rate based on the specified balance:
interest_rate(200.75);
// => 0.5Implement the yearly_interest function to calculate the interest based on the specified balance:
yearly_interest(200.75):
// => 1.003750Implement the annual_balance_update function to calculate the annual balance update, taking into account the interest rate:
annual_balance_update(200.75);
// => 201.75375Implement the years_until_desired_balance function to calculate the minimum number of years required to reach the desired balance, taking into account that each year, interest is added to the balance.
This means that the balance after one year is: start balance + interest for start balance.
The balance after the second year is the balance after one year + interest for the balance after one year.
And so on, until the current year's balance is greater than or equal to the target balance.
double balance {200.75};
double targetBalance {214.88};
years_until_desired_balance(balance, targetBalance)
// => 14Note that the value returned is an int.