|This is very straightforward stuff and you've already been told how to do it, so it's difficult to know where you are going wrong. The best thing to do is to list the program that you have written; then we can have a look and see what you are doing wrong and give you a few hints. There's no point in us just listing a solution as you'll learn nothing that way.|
Also it would be helpful to know which C/C++ compiler you are using and which Operating System. I'm quite happy to point you in the right direction once I see what you have tried so far.