Thread: finding amount of cobalt need help

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    14

    finding amount of cobalt need help

    Question:
    The rate of decay of a radioactive isotope is given in terms of its half time H, the time lapse required for the isotope to decay to one-half of its original mass.The isotope cobalt-60 has a half-life of 5.272 years. Compute and print in table form the amount of this isotope that remains after each year for 5 years, given the initial presence of an amount in grams. the value of amount should be provided interactively. the amount of cobalt-60 remaining can be computed by using the following formula: r=amount X C^(y/H) where amount is the initial amount in grams, c is expressed as e^-0.693 (e=2.71828), y is the number of years elapsed, and H is the half-life of the isotope in years.
    Code:
    #include <stdio.h>
    #include <math.h>
    int 
    main(void)
    {
    int year;
    double cobalt_initial;
    printf("Please enter the initial amount of Cobalt> ");
    scanf("%lf", &cobalt_initial);
    printf(" Year     Amount Total\n");
    for (year = 0; year <= 5; year += 1){
    cobalt_initial = cobalt_initial - cobalt_initial * exp((-.0693)*(year/(5.272)));
    printf("%6c%d%8c%.2f\n", ' ', year, ' ', cobalt_initial);
    }
    return(0);
    }
    the program, instead of making a table for every year does this:
    Please enter the initial amount of Cobalt> 200
    Year Amount Total
    6 0.00
    Please help me identify the problem and tell me what to do. Thank you!

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The first iteration through the loop year is zero, so the argument to exp() is zero. exp(0) is always 1. So the first time through the loop sets cobalt_initial to zero. On subsequent iterations, since cobalt_initial is zero, it's value doesn't change - cobalt_initial is a common factor in all terms of the expression.

    The code should print six lines, with a value of cobalt_initial being zero for each year. If you are not getting that, you have a version control problem.


    And your code formatting is atrocious.

    I've described what the code is doing. It is your job to make it do what you intend, not mine.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    14
    I fixed the equation. How can I fix the version control problem, it doesn't print six lines. Please help me. It seems like I did everything right....I'm confused. Thanks for any help!

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Make sure the code you're working with is identical to what you posted. Make the required changes. Then delete the executable and object files. Recompile the code and link.

    If using an IDE (Integrated Development Environment, like CodeBlocks, Visual Studio, or whatever it is you are using) do "Build Clean" (to delete the executable and object files) followed by "Build All" (to recompile and link). [The wording of those actions in quotes vary between IDEs, but the idea is the same].
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You should know that this is C, not C++, so please post in the C section next time.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. binary - get amount 1's
    By thescratchy in forum C Programming
    Replies: 2
    Last Post: 02-26-2011, 05:26 PM
  2. Displaying amount of ram?
    By trancedeejay in forum C Programming
    Replies: 8
    Last Post: 01-21-2006, 03:45 PM
  3. Replies: 3
    Last Post: 06-25-2003, 04:29 PM
  4. amount of allocated memory...
    By lobo in forum Windows Programming
    Replies: 2
    Last Post: 06-20-2002, 10:18 PM
  5. How to find the amount of memory
    By Prakash in forum C Programming
    Replies: 1
    Last Post: 09-18-2001, 11:12 AM