Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

installment - float error C2296

Tags:

c++

I have this function:

    float ObliczRate(float fKwotaKredytu, float fOprocentowanie, int iIloscRat)
{
    /*
    Rata = K * y^n * (y-1) / (y^n-1);

    y = 1 + (r / 12)
    */

    float fRata, float fY;

    fY = 1 + (fOprocentowanie / 12); // obliczanie stałej kredytu
    fRata = fKwotaKredytu * fY^iIloscRat * (fY - 1) / (fY^iIloscRat - 1); // obliczanie raty stałej ze wzoru

    return fRata;
}

And i have error: "error C2296: '^' : illegal, left operand has type 'float'" only on "(fY^iIloscRat - 1)". What's wrong with this?

like image 301
Saibamen Avatar asked Aug 27 '26 11:08

Saibamen


2 Answers

It's because ^ is not an exponential operator, but the bitwise XOR operator. You want the std::pow function.

like image 106
Some programmer dude Avatar answered Aug 30 '26 00:08

Some programmer dude


In C++ the operator ^ has a meaning of bitwise XOR operator not the power operation. You will have to use the pow function defined in the cmath header here.

like image 44
Ivaylo Strandjev Avatar answered Aug 30 '26 00:08

Ivaylo Strandjev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!