I'm also having problems on doing a program like this...

I can't actually figure out the logic...Could anyone give me a hint?