Half life program

Carbon-14 is constantly produced in Earth’s upper atmosphere
due to interactions between cosmic rays and nitrogen, and is found in all plants and animals.
After a plant or animal dies, its amount of carbon-14 decreases by about .012%
per year. Determine the half-life of carbon-14, that is, the number of years required for
1 gram of carbon-14 to decay to less than ½ gram.

any hints on the math for this problem?
im not sure how to use ln in microsoft visual studios either.
closed account (48T7M4Gy)
You don't need logarithms. Just generate a table of values showing the diminishing amount of C14 each year for 10000 years and read off the year number when 1/2 a gram is reached. You can go one better and use an if statement and only display if the weight is less than 1/2 gram
Last edited on
1
2
3
4
5
6
7
8
9
10
when t = 0,
amt = 1

when t = 1,
amt = 1 * 0.9988
    = 0.9988

when t = 2,
amt = (0.9988) * 0.9988
    = 0.9988^2

See the pattern?
Using logarithm and algebra you should be able to solve it. If you have any trouble, post what you're confused on and we'll try to help.

You could also use a while-loop to do it as well.
1
2
3
4
5
const double starting_amt = 1.0, end_amt = 0.5, decay_rate = 0.0012;
int n_years = 0; double current_amt = starting_amt;
while( current_amt > end_amt ) {
    // code here
}
Last edited on
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.999882
After 3 years, fraction remaining = 0.999883
....
After n years, fraction remaining = 0.99988n

For the half life of n years, you want a fraction remaining of 0.5. So,

0.5 = 0.99988n

Take logs (to any base):
log(0.5) = log (0.99988n)
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.
closed account (48T7M4Gy)
Hint:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

int main()
{
    double decay_rate = .012/100; // Let the machine work it out :)
    double ??? = ???;
    int count = 0;
    
    while( (mass *=  ???) > ??? ){
        ???++;
    }
    std::cout << "After " << ??? << " years " << ??? << " will remain\n";
    
    return 0;
}


After 5775 years 0.499993 will remain
Program ended with exit code: 0
Topic archived. No new replies allowed.