Front Office Football Central  

Go Back   Front Office Football Central > Archives > FOFC Archive
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 03-25-2003, 02:20 PM   #1
Raven
College Prospect
 
Join Date: Oct 2000
Location: Baltimore, MD
a little C programming help?

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?

Raven is offline   Reply With Quote
Old 03-25-2003, 02:38 PM   #2
Franklinnoble
Banned
 
Join Date: Jul 2002
Location: Placerville, CA
"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.
Franklinnoble is offline   Reply With Quote
Old 03-25-2003, 02:41 PM   #3
Fido
High School Varsity
 
Join Date: Aug 2002
Location: New Hampshire, USA
Re: a little C programming help?

Quote:
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 ( I believe) and simply computes the Arctangent of X (meaning that y = atan(x) means that x = tan(y)).
Fido is offline   Reply With Quote
Old 03-25-2003, 03:10 PM   #4
Raven
College Prospect
 
Join Date: Oct 2000
Location: Baltimore, MD
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);
Raven is offline   Reply With Quote
Old 03-25-2003, 03:13 PM   #5
Fido
High School Varsity
 
Join Date: Aug 2002
Location: New Hampshire, USA
Quote:
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);
Fido is offline   Reply With Quote
Old 03-25-2003, 03:14 PM   #6
Fritz
Lethargic Hooligan
 
Join Date: Oct 2000
Location: hello kitty found my wallet at a big tent revival and returned it with all the cash missing
float can't hold a double?
__________________
donkey, donkey, walk a little faster
Fritz is offline   Reply With Quote
Old 03-25-2003, 03:18 PM   #7
Fido
High School Varsity
 
Join Date: Aug 2002
Location: New Hampshire, USA
Quote:
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.
Fido is offline   Reply With Quote
Old 03-25-2003, 03:27 PM   #8
Raven
College Prospect
 
Join Date: Oct 2000
Location: Baltimore, MD
warning: double format, pointer arg (arg 2)


......undefined reference to 'atan'
Raven is offline   Reply With Quote
Old 03-25-2003, 03:29 PM   #9
Nothingman
n00b
 
Join Date: Apr 2002
Location: Chevy Chase, MD
#include < math.h >


Last edited by Nothingman : 03-25-2003 at 03:30 PM.
Nothingman is offline   Reply With Quote
Old 03-25-2003, 03:29 PM   #10
Fido
High School Varsity
 
Join Date: Aug 2002
Location: New Hampshire, USA
Quote:
Originally posted by Raven
warning: double format, pointer arg (arg 2)


......undefined reference to 'atan'


#include < math.h >

at the top of the file

Last edited by Fido : 03-25-2003 at 03:31 PM.
Fido is offline   Reply With Quote
Old 03-25-2003, 03:52 PM   #11
Raven
College Prospect
 
Join Date: Oct 2000
Location: Baltimore, MD
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?
Raven is offline   Reply With Quote
Old 03-25-2003, 03:54 PM   #12
Fido
High School Varsity
 
Join Date: Aug 2002
Location: New Hampshire, USA
Quote:
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.
Fido is offline   Reply With Quote
Old 03-25-2003, 04:28 PM   #13
Raven
College Prospect
 
Join Date: Oct 2000
Location: Baltimore, MD
Thanks a lot Fido.

One last question for anyone...what does this mean " Warning: multi-line string literals are depricated" ?
Raven is offline   Reply With Quote
Old 03-25-2003, 10:06 PM   #14
-Panther
High School Varsity
 
Join Date: Sep 2002
Location: Lost
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.
__________________
Stupidity is an Equal Opportunity Employer.
-Panther is offline   Reply With Quote
Old 03-25-2003, 10:52 PM   #15
sabotai
General Manager
 
Join Date: Oct 2000
Location: The Satellite of Love
"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.
sabotai is offline   Reply With Quote
Old 03-26-2003, 07:49 AM   #16
Fido
High School Varsity
 
Join Date: Aug 2002
Location: New Hampshire, USA
Quote:
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.
Fido is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 05:42 AM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.