View Full Version : a little C programming help?
Raven
03-25-2003, 02:20 PM
I have to write a program in C which takes the radius (entered by user) and calculates the area, diameter and circumference of a circle.
We aren't allowed to set PI as 3.14 but are supposed to computer PI by using the following...
Double atan(double x);
Then compute PI by setting x to 1.0 and then PI = 4.0 * atan(x)
.....problem is we have never went over double or atan so im not exactly sure how to code this part. can anyone help me out?
Franklinnoble
03-25-2003, 02:38 PM
"double" declares an 8-byte numerical variable type... sort of like a "float" on steroids.
"atan" appears to be the name of a function.
Don't take my word for it, though... I'm something of a C novice myself.
Originally posted by Raven
I have to write a program in C which takes the radius (entered by user) and calculates the area, diameter and circumference of a circle.
We aren't allowed to set PI as 3.14 but are supposed to computer PI by using the following...
Double atan(double x);
Then compute PI by setting x to 1.0 and then PI = 4.0 * atan(x)
.....problem is we have never went over double or atan so im not exactly sure how to code this part. can anyone help me out?
double is just an intrinsic type, like float, int, char, etc. Its basically a larger versino of float, with much greater precision and a larger range.
atan(x) is part of the C standard library (<math.h> I believe) and simply computes the Arctangent of X (meaning that y = atan(x) means that x = tan(y)).
Raven
03-25-2003, 03:10 PM
ok, this is what I have...what am I doing wrong here?
float radius, diameter, area, circumference, x, PI;
double atan(double x);
x = 1.0;
PI = 4.0 * atan(x);
Originally posted by Raven
ok, this is what I have...what am I doing wrong here?
float radius, diameter, area, circumference, x, PI;
double atan(double x);
x = 1.0;
PI = 4.0 * atan(x);
float radius, diameter, area, circumference, x, PI;
x = 1.0;
PI = 4.0 * atan(x);
Fritz
03-25-2003, 03:14 PM
float can't hold a double?
Originally posted by Fritz
float can't hold a double?
the conversion between intrinsic tyoes is automatic. it will generate a compiler error about possible loss of data. The problem is haveing the double atan(double x); line. Probably causing a local function definitions not allowed error.
Raven
03-25-2003, 03:27 PM
warning: double format, pointer arg (arg 2)
......undefined reference to 'atan'
Nothingman
03-25-2003, 03:29 PM
#include < math.h >
Originally posted by Raven
warning: double format, pointer arg (arg 2)
......undefined reference to 'atan'
#include < math.h >
at the top of the file
Raven
03-25-2003, 03:52 PM
OK, I got it. I was using Math.h, but I wasnt using -lm when compiling so it wasn't linking the math library.
Thanks guys.
so I dont need to use Double atan(double x); ?
Even though that is what he is asking of us?
Originally posted by Raven
OK, I got it. I was using Math.h, but I wasnt using -lm when compiling so it wasn't linking the math library.
Thanks guys.
so I dont need to use Double atan(double x); ?
Even though that is what he is asking of us?
That's just the function prototype, basicalling the compiler that somewhere there is a functin called atan whochi accepts a single parameter of type double and returns a double.
You are using it in fact, its in math.h somewhere.
Raven
03-25-2003, 04:28 PM
Thanks a lot Fido.
One last question for anyone...what does this mean " Warning: multi-line string literals are depricated" ?
-Panther
03-25-2003, 10:06 PM
Unless you're required to define floats. define your variables as doubles. I'd assume he expects you to use define doubles since he has you using a the function atan (takes and returns a double)
that would eliminate useless "possible loss of data" warnings.
sabotai
03-25-2003, 10:52 PM
"One last question for anyone...what does this mean " Warning: multi-line string literals are depricated" ?"
Hmm....make sure you have all the proper quotation marks in the right place. Sounds like you may have missed one, and this caused the string to go on for several lines.
Originally posted by Raven
Thanks a lot Fido.
One last question for anyone...what does this mean " Warning: multi-line string literals are depricated" ?
Make sure all of your quotation marks match up. Sounds to me like you missed one.
vBulletin v3.6.0, Copyright ©2000-2026, Jelsoft Enterprises Ltd.