0

When I try to run this code through the compiler, I get the error:

expression result unused 

referring to the line

cents - 25; 

How do I fix this error? How exactly do I "use" the expression result? I tried assigning it to a variable, but that didn't work because the variable cents wasn't updated so the loop kept running forever.

while (cents > 25)
{
    cents - 25 ;
    count++ ;
}
4

It's because you did a calculation and didn't do anything with it. You have cents - 25; Where are you putting the result?

All of these would work:

int change = cents - 25;
cents = cents - 25;
cents -= 25;

The infinite loop is another story. To fix that loop, you'd use either of the latter two.

If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .