Decrease by 0.012%, or decimal fraction 0.00012 (careful of the factor of 10, @integralfx) per year. This leaves a fraction 0.99988 of that at the start of the year.
So after 1 year, fraction remaining = 0.99988
After 2 years, fraction remaining = 0.99988
2
After 3 years, fraction remaining = 0.99988
3
....
After n years, fraction remaining = 0.99988
n
For the half life of n years, you want a fraction remaining of 0.5. So,
0.5 = 0.99988
n
Take logs (to any base):
log(0.5) = log (0.99988
n)
or, by the laws of logs
log(0.5) = n.log (0.99988)
Rearrange for the half life as
n = log(0.5) / log (0.99988)
You can use any base of logarithms (as long as you are consistent). However, most people will use the natural logarithm.
For the C++ function see
http://www.cplusplus.com/reference/cmath/log/
Google "half life of carbon-14" to check your answer.