Author Topic: Problems with Math.h  (Read 12437 times)

strykul

  • Guest
Problems with Math.h
« on: January 21, 2012, 01:35:47 pm »
Hi all :)
I have some troubles with pow function and <math.h> in Code:Blocks.
My code:
Code
#include <stdio.h>
#include <math.h>
int main(void)
{

 struct okrag    /* definicja struktury*/
{
    float x,y, promien;
    char kolor[20];
};
 struct prostokat
{
    float x1,y1,x2,y2;
    char kolor[20];

};

    struct okrag o1,o2; /*deklaracja struktur typu okreg*/

 printf("Insert r1 and R1: ");
    scanf("%f %f %f", &o1.x, &o1.y, &o1.promien);
 printf("Insert r2 and R2:");
    scanf("%f %f %f", &o2.x, &o2.y, &o2.promien);

/*obliczenie ogleglosci pomiedzy srodkami okregow:*/
float odleglosc = sqrt((pow (o1.x-o2.x), 2)+ pow ( (o1.y-o2.y), 2));


if (odleglosc <=(o1.promien+o2.promien))
    printf ("Okregi maja czesc wspolna. \n");
else if (odleglosc=(o1.promien+o2.promien))
    printf ("Okregi sa styczen");
else
    printf("Okregi sa rozlaczne. \n");
return 0;
}

(some comments are in Polish)
Now:

Code
~~\test1.c||In function 'main':|
~~\test1.c|26|error: too few arguments to function 'pow'|
||=== Build finished: 1 errors, 0 warnings ===|

BUT, when i pasted that code into Linux terminal and used gcc with [-lm] parameter, there were no errors.

My question is: can U tell me how to add that parameter to compiler in C:B? (or make my code working).

Best wishes,

Strykul
 


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Problems with Math.h
« Reply #1 on: January 21, 2012, 01:53:43 pm »
Please read this: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29
The enabled all warnings in the project. If you don't have a project, just create one.
Then read the warnings very carefully and the error!
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Problems with Math.h
« Reply #2 on: January 21, 2012, 02:27:49 pm »
BUT, when i pasted that code into Linux terminal [...] there were no errors.

I don't believe it, because the code you have pasted here is not correct.
That's the cause for the compiler error.

After fixing it, the code compiles fine (with  one warning).

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Problems with Math.h
« Reply #3 on: January 21, 2012, 02:46:05 pm »
Code
float odleglosc = sqrt((pow (o1.x-o2.x), 2)+ pow ( (o1.y-o2.y), 2));
~~\test1.c|26|error: too few arguments to function 'pow'|
That's all you need to see/know. After reading the error, count the number of arguments to pow and fix it.

Please note that this is not a "we make other's homework" forum, but a forum dedicated to the development and use of Code::Blocks. Next time, please search an appropriate forum - there are plenty of pure C/C++ forums that are there for help. As Code::Blocks supports a huge variety of compilers we cannot and will not discuss compiler/linker errors not dedicated to compiling Code::Blocks - please understand. That's what you agreed to when registering with the forum btw...

Topic locked.
« Last Edit: January 21, 2012, 02:51:55 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ