User forums > Using Code::Blocks

Pow and Math.h

(1/3) > >>

ultrabot90:
Made console project.
I tried to used pow() function.
Didnt work.
Nor did any math.h function.
In fact, it does not detect any math.h file.
What should I do?
-regards,
ultrabot90

killerbot:
1) C++ project ?
2) assuming yes on 1)

in your cpp file :
#include <cmath>

using namespace std;

TDragon:
Please post a small example of the code that doesn't work, and the contents of the Build log tab in the Messages area, after a failed build.

ultrabot90:
*smashes head*
Sorry for being so damn unspecific. -_-'
Its C++.
Cmath worked, thanks.
And now same program, new problems.

--- Code: ---#include<iostream>
#include<cmath>
using namespace std;
void series(int, int);
int main()
{
    int x, n;
    cout<<"\nEnter the value of x & n…\n";
    cin>>x>>n;
    series(x, n);
    return 0;
}
void series(int x, int n)
{
    int sum=1,f=1,j;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=(2*n-1);j--)
        f*=j;
        sum+=f/pow(x,i); //Line 20
    }
    cout<<"\n"<<sum;
}
--- End code ---
Line 20 - Error - Call of overloaded function 'pow(int&, int&)' is ambigous
Help please.

darkwalk:
http://cppreference.com/stdmath/pow.html

from the reference, pow takes arguments:   double base, double exp

Instead, your function is invoked using something else.  Cast your second argument into a double, adn you should be good.

Navigation

[0] Message Index

[#] Next page

Go to full version