Thread: compound interest, need help

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    11

    compound interest, need help

    this is a program i wrote to count the compound interest, but it's not working it's giving me following error message when i compile
    "compound.c:(.text+0x69): undefined reference to `pow'
    collect2: ld returned 1 exit status"

    following the code
    Code:
         #include <stdio.h>
         #include <math.h>
    
         int mian()
         {
    
             int rate;
             int amount;
             int p;
             int n;
             p=24;
             printf("Rate\t\tAmount");
    
             for(rate=5;rate<=10;rate++){
    
                for(n=1; n<=381; n++){
                   amount=p*pow(1+(rate/100),n);
                   printf("%d\t\t%d", rate,amount);
                  }
             }
               return 0;
         }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well your code isn't a copy/paste of your code, you spelt main wrong.

    In any case, you need to compile with
    gcc prog.c -lm

    The last bit is "minus-el-em".
    It tells the linker to also include the math library, where pow() will be defined.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    11
    Quote Originally Posted by Salem View Post
    Well your code isn't a copy/paste of your code, you spelt main wrong.

    In any case, you need to compile with
    gcc prog.c -lm

    The last bit is "minus-el-em".
    It tells the linker to also include the math library, where pow() will be defined.
    Thank for your help, but when i am compiling its telling me "NO SUCH FILE OR DIRECTORY"
    this how i am compiling gcc compound.c -lm compound

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    gcc compound.c -lm compound
    And what file, pray tell, is compound? Did you mean this?

    gcc compound.c -lm -o compound

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    11
    Thanks for you help it's compiling now but result is not what I want. It's giving me some weird number. once last time just check the coding and see if everything seem correct.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    rate/100
    this is integer division and the result is 0 for your rate values
    use sth. like this
    Code:
    amount=p*pow(1+(rate/100.0),n);
    Kurt

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    -l options should be the last on the list. They don't affect any arguments to their right.

    Also consider adding a '\n' to the end of your printf(), or another '\t' or something. Otherwise the numbers will run together.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Aug 2007
    Posts
    11
    this program of mine is not working, please help me fix it. Its not giving what I am expecting.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well what is your latest code?
    What numbers do you enter for input?
    What numbers do you get for output?
    What numbers were you expecting?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-11-2009, 12:54 PM
  2. need help with compound interest
    By JoelearningC in forum C Programming
    Replies: 4
    Last Post: 03-09-2008, 10:32 AM
  3. Compound Interest Formula
    By veronicak5678 in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2007, 05:16 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. compound interest
    By bliznags in forum C Programming
    Replies: 11
    Last Post: 03-20-2005, 01:46 AM