Thread: pow function not working

  1. #1
    Registered User
    Join Date
    Mar 2004

    pow function not working

    This is supposed to be a very simple program but for some reason I cannot get the pow function to work. I keep on coming up with an error that states
    "could not find a match for pow(float), am I missing something? Thanks.

    // Basic C++ info
    #include <iostream>
    #include <string>
    #include <math.h>
    using namespace std;
    // Declare Global Variables
    float fltNumbac, fltBacpresent, fltDays;
    // Modules
    void MainMenu();
    void BacteriaLoop();
    int main()
    	cout << "Day     Number of Bacteria Present" << endl;
    	return 0;
    void MainMenu()
    	cout << " Welcome to the WilliamK99 Bacteria Calculator!" << endl;
    	cout << " How Many Bacteria are Present at the Start of the Experiment?";
    	cin >> fltBacpresent;
    void BacteriaLoop()
    	while (fltDays <=10)
    		fltNumbac = fltBacpresent * pow(fltDays / 10);
    		cout << fltDays << "           " << fltNumbac << endl;

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    You need to link with libm, so add "-lm" to your commendline, e.g.:
    gcc x.c y.c -lm
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    I think the problem is that pow() takes two arguments, the base and the exponent, but you are passing only one argument.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Katy, Texas
    The error is because you are calling pow() wrong, and the C++ compiler cannot find a template for the pow() function with one parameter.

    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    If you want to exponentiate using base e, use exp() instead of pow(). pow() takes two arguments.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Thanks I changed
    fltNumbac = fltBacpresent * pow(fltDays / 10);


    fltNumbac = pow(fltBacpresent, fltDays/10);

    and it worked like a charm.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM