clear; clc;

b = 100;
r = 0.1;
g = 200;

[years, final_balance] = compounding(b, g, r)

function [holding_years, balance] = compounding(balance, goal, r)

    holding_years = 0;

    while balance < goal
        balance = balance * (1 + r);
        holding_years = holding_years + 1;
    end

end