Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C++ power function help!

Options
  • 26-02-2008 6:42pm
    #1
    Registered Users Posts: 4,502 ✭✭✭


    Hi i am a novice user to c++ program. I have an equation that i need to raise to the power of -2. How do I write this? I have tried writing as follows:

    x=POWER(equation, (p))

    where p is the power i want to raise the equation to.

    This does not seem to be working. I am getting an error that the POWER identifier is not found. I tried defining POWER as a float but this did not work either. The program itself does work, i know that much. :rolleyes:

    Any body got any help? i am a novice user so dont know too much about this and I know it is a simple fix but can get it


Comments

  • Closed Accounts Posts: 4,564 ✭✭✭Naikon


    Just use the inbuilt pow C function or use a for loop.
    The syntax in C has to follow something similar to this:

    power = pow( x , y );

    Where pow returns say x as above to the power y and stores the value
    in the variable named power. Declare the variables as double int's though to reduce the risk
    of overflow.
    EDIT, I see you are raising to a negetive power.


  • Registered Users Posts: 4,502 ✭✭✭chris85


    Naikon wrote: »
    Just use the inbuilt pow C function or use a for loop.
    The syntax in C has to follow something similar to this:

    power = pow( x , y );

    Where pow returns say x as above to the power y and stores the value
    in the variable named power. Declare the variables as double int's though to reduce the risk
    of overflow.
    EDIT, I see you are raising to a negetive power.


    Ok hows this look,

    POWER=pow((2*log(Re*sqrt(f_old))-0.8), -2);
    f_new=POWER;

    seems to work ok in the program.


  • Closed Accounts Posts: 4,564 ✭✭✭Naikon


    chris85 wrote: »
    Ok hows this look,

    POWER=pow((2*log(Re*sqrt(f_old))-0.8), -2);
    f_new=POWER;

    seems to work ok in the program.

    It works:)


Advertisement