Jump to content

  • Log In with Google      Sign In   
  • Create Account

Error: Expression must be a modifiable lvalue


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1   Members   

108
Like
0Likes
Like

Posted 17 January 2013 - 03:29 PM

I've looked around gamedev some and it seems like there's a really supportive community, so I decided to try getting support on this error I'm getting.

 

I'm learning C++ from a book; I'm just beginning in it, so this is a really simple program. The idea is: the user enters a number, which the computer guesses at. However, in the section where I'm modifying the ai's guessing logic, I'm getting an error I can't find a good way to get around. I included a picture of the code and error. When I hover my mouse over the variables "guess" in the arithmetic within the 'if' blocks, it says: "Error: Expression must be a modifiable lvalue"

 

I would really appreciate an explanation of what that means and maybe a suggestion to fix it.

Many thanks in advance for helpful replies.

Attached Thumbnails

  • Aiguesserror.PNG


#2   Moderators   

9748
Like
3Likes
Like

Posted 17 January 2013 - 03:46 PM

Quickfix:
Use a=4+b over 4+b=a.
You cannot assign the value a into 4+b.

If both a=4+b and 4+b=a are to be the same, then which value should be assigned to the other in the expression: a=b?
You can read more about l-values and r-values here.

Also:
You only need to call srand once in your program, please refer to this thread: Why is it bad to call srand multiple times?

Edited by fastcall22, 17 January 2013 - 03:54 PM.

zlib: eJzVVLsSAiEQ6/1qCwoK i7PxA/2S2zMOZljYB1TO ZG7OhUtiduH9egZQCJH9 KcJyo4Wq9t0/RXkKmjx+ cgU4FIMWHhKCU+o/Nx2R LEPgQWLtnfcErbiEl0u4 0UrMghhZewgYcptoEF42 YMj+Z1kg+bVvqxhyo17h nUf+h4b2W4bR4XO01TJ7 qFNzA7jjbxyL71Avh6Tv odnFk4hnxxAf4w6496Kd OgH7/RxC

#3   Members   

108
Like
0Likes
Like

Posted 17 January 2013 - 03:58 PM

Thank you, this is very helpful






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.