User forums > Using Code::Blocks

Problems with Math.h

(1/1)

strykul:
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;
}
--- End code ---

(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 ===|
--- End code ---

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
 

oBFusCATed:
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!

Jenna:

--- Quote from: strykul on January 21, 2012, 01:35:47 pm ---BUT, when i pasted that code into Linux terminal [...] there were no errors.

--- End quote ---

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).

MortenMacFly:

--- Quote from: strykul on January 21, 2012, 01:35:47 pm ---
--- Code: ---float odleglosc = sqrt((pow (o1.x-o2.x), 2)+ pow ( (o1.y-o2.y), 2));

--- End code ---
~~\test1.c|26|error: too few arguments to function 'pow'|

--- End quote ---
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.

Navigation

[0] Message Index

Go to full version