Author Topic: Pow and Math.h  (Read 30739 times)

Offline ultrabot90

  • Single posting newcomer
  • *
  • Posts: 8
Pow and Math.h
« on: May 23, 2007, 04:34:20 pm »
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
Code::Blocks ownz. The corporate dogs be screwed.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5272
Re: Pow and Math.h
« Reply #1 on: May 23, 2007, 04:38:29 pm »
1) C++ project ?
2) assuming yes on 1)

in your cpp file :
#include <cmath>

using namespace std;

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Pow and Math.h
« Reply #2 on: May 23, 2007, 04:39:21 pm »
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.
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline ultrabot90

  • Single posting newcomer
  • *
  • Posts: 8
Re: Pow and Math.h
« Reply #3 on: May 23, 2007, 05:17:11 pm »
*smashes head*
Sorry for being so damn unspecific. -_-'
Its C++.
Cmath worked, thanks.
And now same program, new problems.
Code: [Select]
#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;
}
Line 20 - Error - Call of overloaded function 'pow(int&, int&)' is ambigous
Help please.
Code::Blocks ownz. The corporate dogs be screwed.

Offline darkwalk

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: Pow and Math.h
« Reply #4 on: May 23, 2007, 05:21:39 pm »
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.

Offline ultrabot90

  • Single posting newcomer
  • *
  • Posts: 8
Re: Pow and Math.h
« Reply #5 on: May 23, 2007, 05:25:08 pm »
thx! ^_^
Code::Blocks ownz. The corporate dogs be screwed.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5272
Re: Pow and Math.h
« Reply #6 on: May 23, 2007, 05:30:03 pm »
and important !!!

Your code is actually not correct. You have to specify to use the std namespace (always do this in cpp files, never headers).

You can :

a) using namespace std;

or specify just what you need :
b)
using std::cout;
using std::cin;
using std::pow;

Offline ultrabot90

  • Single posting newcomer
  • *
  • Posts: 8
Re: Pow and Math.h
« Reply #7 on: May 23, 2007, 06:08:25 pm »
I think I did type in the "using namespace std;" line...
Another problem is that C::B always returns a "Warning : No newline at end of file."
Its there in any program I do. Even the previous one.
Thats the entire lot of problems, I think.
Code::Blocks ownz. The corporate dogs be screwed.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5272
Re: Pow and Math.h
« Reply #8 on: May 23, 2007, 06:38:41 pm »
it's no CB that's bugging you, it's the compiler.
A lot of compilers want all files to end with an empty line.

Just make a (good) habit out of it ;-)

Offline ultrabot90

  • Single posting newcomer
  • *
  • Posts: 8
Re: Pow and Math.h
« Reply #9 on: May 23, 2007, 07:10:42 pm »
oO
Ok...That did the trick.
Thanks.
Code::Blocks ownz. The corporate dogs be screwed.

Offline transfrank

  • Single posting newcomer
  • *
  • Posts: 6
Re: Pow and Math.h
« Reply #10 on: March 15, 2008, 05:21:42 am »
Hello,
I did
Code: [Select]
#include <cmath>
using name space std;

and upon compilation, code::blocks opens up the cmath file and gives the following error message for all the math functions, (e.g. like for arc cosine):
Code: [Select]
error '::acos' has not been declared
Also, I added under Project build options-> linker settings->link libraries : m for math.
Advice on what us wrong?
Thanks,
Frank

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7066
    • My Best Post
Re: Pow and Math.h
« Reply #11 on: March 15, 2008, 10:01:40 am »
Code: [Select]
#include <cmath>
using name space std;

It is namespace not name space!

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline transfrank

  • Single posting newcomer
  • *
  • Posts: 6
Re: Pow and Math.h
« Reply #12 on: March 15, 2008, 06:17:26 pm »
I did namespace in the code and just typed it too quickly here. So my problem persists.