Displaying the error message "expression must be integral or enumerated type" in C ++

I have the following code and I get an error in this equation:

v=p*(1+r)^n.

Please help me find the cause of this error.

# include <iostream>
# include <limits>

using namespace std;

int main()
{
    float v,p,r;
    int n;

    cout<<"Enter value of p:";
    cin>>p;
    cout<<"Enter value of r:";
    cin>>r;
    cout<<"Enter value of n:";
    cin>>n;

    v=(p)*(1+r)^n; // here i am getting error message as "expression must have integral or enum type"

    cout<<"V="<<v;

    std::cin.ignore();
    std::cin.get(); 
}
+4
source share
3 answers

C ++ 11 5.12 - Bitwise exclusive operator OR

exclusive or self-expression: and expression Exclusive expression or expression 1 Conventional arithmetic conversions are performed; the result is a bitwise exclusive OR operand function. The operator is applicable only to the integral or non-enumerated operands of an enumeration.


If you want to calculate v = (p) * (1 + r) n , you need to change

v=(p)*(1+r)^n;

to

v = p * powf(1+r, n); // powf: exponential math operator in C++

C++, ^ XOR ( ) , . a = 2 ^ 3; // a will be 1.

.

+8

, ^ ++, xor. integer/enum.

, powf

powf(p * (1 + r), n)

// Or possibly the following depending on how you want the
// precedence to shake out
p * powf(1 + r, n)
+7

OR ^

( ++)

0
source

All Articles