# Illegal use of floating point...(In C)

• 05-31-2003
OmnipotentCow
Illegal use of floating point...(In C)
Hello, I have just got into learing to program (In C), and I'm having a problem with floating point.

It's a simple get the volume of a circle if given a radius problem.

#include <stdio.h>

char user[100];
const float PI = 3.1415;
float volume;

int main()
{
fgets(user, sizeof(user), stdin);

volume = ((4.0 / 3.0 * PI) * radius) ^ 3.0;

printf("The volume of the circle is %f\n", volume);
return (0);
}

Now I don't know if this message board has problems with posts having source code in them, but it's a short program, so don't kill me.

What I want to know from anyone that knows C, is to tell me if I did anything wrong, because when i compile the code, it brings up a error message saying illegal use of float point.

I belive the problem lies in with the squaring the problem by 3. Maybe you can't square floating point numbers? Or a special function or key to do it?

• 05-31-2003
OmnipotentCow
Thank you, that fixed the problem. Seems this book I'm learning from decided that learning ^ is integer exclusive isn't that important.

And no, I did not read that post. Thanks for the info though.
• 05-31-2003
quzah
Quote:

Originally posted by OmnipotentCow
Thank you, that fixed the problem. Seems this book I'm learning from decided that learning ^ is integer exclusive isn't that important.

And no, I did not read that post. Thanks for the info though.

*evil grin* Use a union!
Code:

union foobar
{
unsigned int foo;
float bar;
};

My output is:

bar = 123.456001
bar = 123.521919

As you can see, floating point numbers themselves just plain suck for precision. That aside, you can see that XOR does have some effect, but not what you'd hope. Still, it's an amusing exercise.

Quzah.
• 05-31-2003
WaltP
Quote:

Originally posted by OmnipotentCow
Thank you, that fixed the problem. Seems this book I'm learning from decided that learning ^ is integer exclusive isn't that important.
It's not that ^ is integer specific, it's that ^ is not to the power of. Looks like you learned Basic first where 3 ^ 2 means 3 squared.
• 05-31-2003
quzah
Quote:

Originally posted by WaltP
It's not that ^ is integer specific, it's that ^ is not to the power of. Looks like you learned Basic first where 3 ^ 2 means 3 squared.
It is integer specific. It can only be used on integeral data types. (IE: int, long, char) It cannot be used on floating point or decimal values.

Quzah.
• 05-31-2003
XSquared
I think that he meant that it wasn't the main issue here. The issue was confusing ^ and pow( ).