Jump to content
  • Advertisement
Sign in to follow this  
Stickmunkee

Error: Expression must be a modifiable lvalue

This topic is 2152 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

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.

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!