I have a function which has an integer as a formal parameter:
string function1(int hundreds)
{
// some code
else if (hundreds > 9)
{
hundreds - 5;
}
When I compile this code, I get a warning message located at the binary minus operator saying 'expression result unused'. What causes this warning message to be thrown?
My guess is that it is not good practice to minus a constant integer, and instead, I should have defined a variable of type const int
which has a value of 5
and taken this away from hundreds
instead. i.e instead of hundreds - 5
I should have used:
const int DEDUCTION = 5;
//code up to the following statement
hundreds - DEDUCTION;
You should either assign the result to another variable or assign it back as hundreds -= 5;
. Otherwise the result is simply dropped.