Responses for exercises in Exercism.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
813 B

using System;
static class SavingsAccount
{
public static float InterestRate(decimal balance)
{
float interest = 0.5F;
if (balance >= 5000) {
interest = 2.475F;
} else if (balance >= 1000) {
interest = 1.621F;
} else if (balance < 0) {
interest = -3.213F;
}
return interest;
}
public static decimal AnnualBalanceUpdate(decimal balance)
{
return (balance * (decimal)(Math.Abs(InterestRate(balance) / 100))) + balance;
}
public static int YearsBeforeDesiredBalance(decimal balance, decimal targetBalance)
{
int years = 0;
while (balance < targetBalance) {
years += 1;
balance = AnnualBalanceUpdate(balance);
}
return years;
}
}