0

I have a simple method that takes 3 arguments (target balance, current balance, interest rate). The method is supposed to calculate the time it would take (in years) to reach the target balance. I know the formula is correct since it prints out correctly but it fails on a assertion for some reason.

Here is my code:

double count_years(double t, double b, double r); //Declaration
double account::count_years(double t, double b, double r) {
    double years = (1/(r/100)) * ((t/b) - 1);
    return years;
}

I'm checking the code using this as an assertion and getting an error:

assert(a.count_years(60, 50, 0.1) == 200);

Error Message:

assertion "a.count_years(60, 50, 0.1) == 200"

Muhammad Ali
  • 3,478
  • 5
  • 19
  • 30

0 Answers0