Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

noob question about getting roots (math)

Status
Not open for further replies.

torturedmind

Programmer
Jan 31, 2002
1,052
PH
what's wrong with this simple code? the answer is always the base (16) when it should be 4.
Code:
int main()
{
    int iBaseNum = 16, iRootNum = 2;
    float fAnyAnswer = 0.0f;
    fAnyAnswer = iBaseNum^(1/iRootNum);
    cout << fAnyAnswer;

    return 0;
}

am a newbie in c++. thanks in advance for any help you'll all extend.

kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
^ is for XOR not exponents. Use the pow() function instead.

Also, you are using integers which don't support fractions (i.e. 1/2). Use double instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top