Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,271 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,450 people online right now. Registration is fast and FREE... Join Now!




using M_E

 
Reply to this topicStart new topic

using M_E

jaclyn_85
14 Oct, 2006 - 06:50 PM
Post #1

New D.I.C Head
*

Joined: 16 Sep, 2006
Posts: 17


My Contributions
edit: added [code] tags ~ jayman9

This post has been edited by jaclyn_85: 15 Oct, 2006 - 07:55 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Using M_E
14 Oct, 2006 - 07:45 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
What does M_E represent?

Is it a constant and if so where have you defined it?
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Using M_E
14 Oct, 2006 - 10:30 PM
Post #3

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,914



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
To jayman9:
M_E is a Standard Constant that stands for the value of e (2.71828...)
It is defined in the math.h or the cmath header file.

To jaclyn_85:
You don't need to place M_E in the variable e, since you're not using e anywhere in the program.

There were a lot of unterminated strings in the printf statement as well as missing semicolons.

Besides that, there is one major mistake.
CODE

population = 1 * ( M_E ^ (( 1 - k ) * generations ));

Unlike BASIC and other languages, in the C/C++ language, the ^ operator stands for a XOR Operation rather than a "power-of" operation.

You need to use the pow() function for this.
Change the above statement to this:
CODE

population = 1 * ( pow(M_E,(( 1 - k ) * generations) ));


The code works fine after that. smile.gif
User is offlineProfile CardPM
+Quote Post

jaclyn_85
RE: Using M_E
15 Oct, 2006 - 05:19 AM
Post #4

New D.I.C Head
*

Joined: 16 Sep, 2006
Posts: 17


My Contributions
QUOTE
There were a lot of unterminated strings in the printf statement as well as missing semicolons.

Besides that, there is one major mistake.
CODE

population = 1 * ( M_E ^ (( 1 - k ) * generations ));

Unlike BASIC and other languages, in the C/C++ language, the ^ operator stands for a XOR Operation rather than a "power-of" operation.

You need to use the pow() function for this.
Change the above statement to this:
CODE

population = 1 * ( pow(M_E,(( 1 - k ) * generations) ));


The code works fine after that. smile.gif



to born2c0de:

When i do that, i get an error message saying "undefined symbol: pow " now.

EDIT : Added Quote Tags - born2c0de
User is offlineProfile CardPM
+Quote Post

jaclyn_85
RE: Using M_E
15 Oct, 2006 - 05:26 AM
Post #5

New D.I.C Head
*

Joined: 16 Sep, 2006
Posts: 17


My Contributions
Whoops, nevermind, forgot -lm ....
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Using M_E
15 Oct, 2006 - 09:01 AM
Post #6

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
QUOTE(born2c0de @ 14 Oct, 2006 - 11:30 PM) *

To jayman9:
M_E is a Standard Constant that stands for the value of e (2.71828...)
It is defined in the math.h or the cmath header file.

Hmm...I looked right past it when I checked the math.h. Damn my old eyes and failing memory.

Thanks for the info born2c0de.
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Using M_E
15 Oct, 2006 - 10:08 AM
Post #7

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,914



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
jaclyn_85, why did you erase the code that you posted first?
The entire topic revolves around the first post, and other members might find it useful...so don't erase anything once you've posted it.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:57PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month