I am getting an error message of "expression result unused" for all of my while loops when I try to run the user input through my greedy algorithm. Any thoughts?
-
That sounds like a compiler error, but you say it happens when you try to run your user input. Can you please clarify step by step exactly where the error occurs?– curiouskiwi ♦Commented Jun 20, 2014 at 23:07
-
Here are a couple of related questions that might help.– AirCommented Sep 23, 2014 at 16:07
-
possible duplicate of How to fix the "expression result unused" compilation error?– kzidaneCommented Jun 28, 2015 at 0:58
-
I am a couple of years behind, but it could be because you forgot to return a value from one of your previous functions. Therefore, it did not allow you to run that particular line of code.– VeronicaCommented Feb 8 at 17:25
2 Answers
Google search of expression result unused
will lead to 2 links :
-
It seems that you have written the number in a wrong way. Have a look at it, you are not supposed to write commas in the numbers. i.e.
int i = 50,000
is wrong way and should be written asint i = 50000
. Remove any such commas from your program. -
Although the link is of for loop but here, re-initialization of the variable used for iterating was not done properly. If variable j is used for iteration, then
j+1
is not the way of re-initialization, may be typo could be its reason, it should bej += 1
orj = j+1
.
Please specify if any of these 2 worked, if not, then need to see the code. You may cut short the code and not disclose whole of it.
-
Had a similar issue and the second solution was my issue as well. Did not re-initialize.– hmitreaCommented Jul 29, 2019 at 19:14
-
My issue was related to link 2 where I had an incorrect definition of re-initialization. Thanks for the tip @sinister Commented Oct 30, 2020 at 21:36
It seems that you define an expression as a result of a computation, and throw it away without assigning it to a variable.