I am the definition of a beginner. I am working with C++ in my school's Linux server. I have been working at this program for a few hours and I can't figure out what I'm doing wrong. I've reassigned variables and restated 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;
}
The error states: invalid operands of types ‘int’ and ‘’ to binary ‘operator<<’
Basically the problem is how cout << avg =(sum / f) << endl
is parsed.
<<
is left associative and has higher precedence than = so the expression is parsed as
(cout << avg) = ((sum/f) << endl)
Now the right hand side of your assignment is int << endl
which raises the error, since the operation makes no sense (<<
it's not defined for int, decltype(endl)
arguments)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With