#include <iostream.h>
#include <math.h>
void main () 
{ 
int n,j,q,d,h,t,i,m,f,b;
cout<<" num of eng";
cin >> j;
q=0;
d=0;
h=0;
t=0;
for (i=1;i<=j;i++)
{cout<< "insert Salary ";
cin>> m;
m /(22) =d;
d/(8) = h;
cout<<"\n Leave ";
cin>>f;
cout<< "\n Attend ";
cin >> b;
f - b = t;
t * h = q;
cout<<"q="<<q;
}
}

Dani AI

Generated

The compiler message "left operand must be an l-value" means the thing on the left side of = must be an assignable object with storage — a variable or a reference. Results of expressions, literals, temporaries and most function return values are r-values and cannot appear on the left. Examples of invalid left‑hand sides: 5 = x, (a + b) = c, std::string("s") = "t", or assigning to the return value of a function that returns by value. As pointed out, putting a computed expression where a simple variable belongs is the immediate cause here.

Correct the code by computing the right-hand expression and storing it in a named, modifiable variable of an appropriate type. If fractional results are expected, use floating-point math rather than integer division. For example, compute hours-per-day with a floating expression such as double hoursPerDay = static_cast<double>(salary) / 22.0 / 8.0; so values aren't truncated. Parentheses can help readability but do not turn an r-value into an l-value.

Style and structure matter for correctness and maintenance. Prefer meaningful names, initialize variables when declared, validate input, and use containers for multiple employees (e.g. std::vector<double> salaries(n); and for (int i = 0; i < n; ++i)). Use standard headers and an int main() that returns a value. These are the same practical improvements advocated and will make the logic and fixes easier to verify.

Quick troubleshooting checklist: confirm the left side of = is a modifiable variable or reference; check for accidental parentheses around the LHS; watch for integer division when a float was intended; enable warnings (e.g. -Wall -Wextra) and fix the first error reported before moving on. The combination of clearer names, correct assignment direction, and proper types resolves the compile error and prevents silent numeric truncation.

Recommended Answers

All 4 Replies

m /(22) =d;
d/(8) = h;

These don't work. You need a single variable on the left. Do whatever algebra you need to to accomplish this:

m =d * 22;
d = h * 8;

or if you are trying to do an assignment to d and h, switch sides:

d = m /(22);
h = d/(8);

This may not be what you want, but it'll compile.

Yea, looking at your code makes my brain hurt.
A) Please read the forum rules on Code tags and....
B) You need to work on your style

>Yea, looking at your code makes my brain hurt.
If you're not exaggerating then you should probably do something about that weak mind. Maybe take up sudoku. ;)

When posting code, the format should look something like this( see below), if it isn't then make it until it is. This is not only help us read
better, but it will also help you get better comments.

//notice not .h
#include <iostream>
#include <cmath>

using namespace std;

int main () 
{ 
  //initialize variable upon decelerations, why aren't you using arrays?
   int n(0),j(0),q(0),d(0),h(0),t(0),i(0),m(0),f(0),b(0);
  
  cout<<" num of eng";
  cin >> j;

  for (i=1;i<=j;i++)
  {
	  cout<< "insert Salary ";
	  cin>> m;
  
	  //you got is in opposite order, its d = m/22    
	  m /(22) =d;//See what VernonDozier said   
	  d/(8) = h;//See what VernonDozier said

	  cout<<"\n Leave ";
	  cin>>f;
  
	  cout<< "\n Attend ";
	  cin >> b;
 
	  f - b = t;
	  t * h = q;

	  cout<<"q="<<q;
  }

  return 0; //main returns something
}

Now look back at your 1st post and look at this post, realize how
much more readable this post is?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.