-
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.
Code:
// 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()
{
MainMenu();
cout << "Day Number of Bacteria Present" << endl;
BacteriaLoop();
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;
return;
}
void BacteriaLoop()
{
while (fltDays <=10)
{
fltNumbac = fltBacpresent * pow(fltDays / 10);
cout << fltDays << " " << fltNumbac << endl;
fltDays++;
}
return;
}
-
You need to link with libm, so add "-lm" to your commendline, e.g.:
--
Mats
-
I think the problem is that pow() takes two arguments, the base and the exponent, but you are passing only one argument.
-
The error is because you are calling pow() wrong, and the C++ compiler cannot find a template for the pow() function with one parameter.
http://www.cppreference.com/stdmath/pow.html
Todd
-
If you want to exponentiate using base e, use exp() instead of pow(). pow() takes two arguments.
-
Thanks I changed
fltNumbac = fltBacpresent * pow(fltDays / 10);
to
fltNumbac = pow(fltBacpresent, fltDays/10);
and it worked like a charm.