View Full Version : Programming language C++
Wei Wu Wei
Nov 4th, 2002, 05:55:38 PM
I can;t get the gosh darned thing to calculate natural logarithms for me. I have 3 programs due tomorrow and I can't get this one to work just because the stupid thing won;t calculate natural logarithms! Can anyone help me?
Nathanial K'cansce
Nov 4th, 2002, 05:56:54 PM
Have the proper header in?
Wei Wu Wei
Nov 4th, 2002, 06:01:34 PM
Header? You mean
#include<math.h> right? I tried that. It said, "Undeclared Identifier and then mentioned something about converting float variable to int variables or something.
Nathanial K'cansce
Nov 4th, 2002, 06:10:19 PM
Hmm...
I'd say try this.. though it might not work, since I don't know what compiler you use, nor the compiler I use up at school.. heh.
#include < math.h > (without the spaces)
then, there is probably some actual function name for the natural log that you need to know.
If not, then make your own fuction that finds the natural log.
Wei Wu Wei
Nov 4th, 2002, 06:16:27 PM
Hmmmm ok.
Sanis Prent
Nov 4th, 2002, 09:01:58 PM
yes....math.h is the library you need to include.
I know there is an embedded function within called pow(x,y), which takes a variable x, raising to a power y. Logarithmic and exponential functions are related in such a way as y = b^x, thus b = log(y) x. You could pull the result of a pow function, and plug it in...I think. There's probably an embedded logarithm function though.
Wei Wu Wei
Nov 4th, 2002, 09:05:47 PM
I'll give that a try. Thanks Sanis.
Sanis Prent
Nov 4th, 2002, 09:06:27 PM
ack you said natural log...and I've no clue regarding irrationals. I can't even remember calling pi in C++, much less the value of e
Wei Wu Wei
Nov 4th, 2002, 09:08:01 PM
for pi in C++ you type in PI. but declare it as a constant. I think.
(goes to check his sucky textbook)
Nathanial K'cansce
Nov 4th, 2002, 09:12:20 PM
Yeah, you declare PI as a constant and type it in before the main block.
the e function = exp(x) I believe. You might be able to use that, since the natual log of a thingy is the sanme as saying that's the exponent that goes on e and gives you this is that.
vBulletin, 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.