into binary" operator << I am the defini...">

Why am I getting this error: Invalid operands of type "int" and "<unresolved overloaded function type> into binary" operator <<

I am the definition of a beginner. I am working with C ++ on my school Linux server. I have been working on this program for several hours and I cannot figure out what I am doing wrong. I have reassigned variables and reformulated my formulas, but nothing works. Please help.

#include<iostream>
#include<string>
using namespace std;

const int f=5;

int main ()
{
        int a,b,c,d,e,sum,avg;
        cout << "Please enter five numbers. " << endl;
        cin >> a >> b >> c >> d >> e;
        sum= a+b+c+d+e;
        cout << "The average of those numbers is: " << endl;
        cout << avg =(sum / f) << endl ;
return 0;
}

      

Error: Invalid operands of types' int and 'to binary' operator <

+3


source share


1 answer


Basically the problem is how it is parsed cout << avg =(sum / f) << endl

.

<<

remains associative and takes precedence over =, so the expression is parsed as



(cout << avg) = ((sum/f) << endl)

      

Now the right side of your assignment int << endl

, which is throwing an error as the operation is meaningless ( <<

it is undefined for arguments int, decltype(endl)

)

+5


source







All Articles