expontants??

This is a discussion on expontants?? within the C++ Programming forums, part of the General Programming Boards category; Ok so can someone help me with adding exponants to a caculator...

  1. #1
    Pokemon Master digdug4life's Avatar
    Join Date
    Jan 2005
    Location
    Mystic Island, NJ
    Posts
    91

    Question expontants??

    Ok so can someone help me with adding exponants to a caculator
    Verbal Irony >>

    "I love english homework!" When really nobody like english homework.
    -Mrs. Jennifer Lenz (English Teacher)

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    14
    how about
    double exp (double) from the <math.h> library
    that is e to the power of x .
    Other functions at
    http://www.opengroup.org/onlinepubs/...sh/math.h.html

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    77
    Just make a loop out of it, something like this:
    Code:
    int Base = 2, Exp = 5, ctr, Result;
    Result = Base;
    for (ctr = 0; ctr < Exp; ctr++)
    {
        Result *= Base;
    }
    That will calculate the value Base to the power of Exp, and puts teh calculated value in Result. That doesn't account for exponents that are less than or equal to 0 (5^0 or 5^-24). But you can easily modify the result to get that.
    So, do you understand everything you know about this yet?

    "Begin at the beginning," the King said, very gravely, "and go on till you come to the end; then stop."

  4. #4
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    Quote Originally Posted by wgdb198
    how about
    double exp (double) from the <math.h> library
    that is e to the power of x .
    Other functions at
    http://www.opengroup.org/onlinepubs/...sh/math.h.html
    Math.h is a header, not a library. And don't use math.h (it's deprecated).

    Instead, use cmath and the std namespace.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21