just joking..well try to think a bit..the average of 2 numbers: A and B is (A+B)/2..or (A+B+C)/3 if you have 3 numbers..ok?
now if you have a lot of numbers(no matter how many),let's say n.you will have (A+B+C+...+n)/n.
That is the theory in math,to write the source code u must have some c++ knowledge.that is something y can't learn you on the forum.Good luck