• Advertisement
Sign in to follow this  

weird error

This topic is 4258 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is a simple problem yet it evades me =(
void Add()
{
     x + y = answer;
     std::cout <<x <<" plus "<< y <<" equals "<< answer"\n";
}


and the errors non-lvalue in assignment expected `;' before string constant Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
LValue = left side value. These are variables you can change.
RValue = right side value. These are variables that you can read.

x + y = answer

It doesn't know how to set (x + y) to anything... thus, it says its not an L-value.

Also, make sure x and y are somewhere in your code. If that is the entire function, x and y must be globals. I'm guessing that you have them somewhere, or it would complain that it doesn't know what x and y are.

So to fix your problem:
answer = x + y;

oh... and in your cout... at the very end you need to change
answer"\n";
to
answer << "\n";
or
answer << std::endl;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement