Ah yes, it seems I misunderstood the problem - you're talking about compound interest with a 5000 sum added every year yes?

In which case, what about this:

int YEARLY_INVESTMENT = 5000;

float INTEREST_RATE = 0.1;

void main()

...int years = 5;

...while(years<=25)

......print valueAt(years);

......years += 5;

int valueAt(int years)

...int sum = 0;

...for(i=0 ; i<years ; i++)

......sum += YEARLY_INVESTMENT;

......sum *= 1+INTEREST_RATE;

Untested and I'm tired so may be making silly mistakes, but I think that should be the gist of it. Feel free to disagree if you think I've done something wrong!