Expression Result Unused Greedy Algorithm

后端 未结 3 1979
南方客
南方客 2021-01-28 08:18

I have run this program and get the error expression result unused. I may be doing something simple wrong, but I have spent the day trying to figure it out to no avail. Any help

3条回答
  •  情话喂你
    2021-01-28 08:28

        if (x >= 25)
        {
            x - 25;               // This accomplishes nothing
            y = y + 1;
        }
        if (x >= 10 && x < 25)
        {
            x - 10;               // This accomplishes nothing
        }   y = y + 1;
        if (x >= 5 && x < 10)
        {
            x - 5;                // This accomplishes  nothing
        }   y = y + 1;
        if (x >= 1 && x < 5)
        {
            x - 1;                // This accomplishes nothing
            y= y + 1;
        }
    

    In each of those lines you're subtracting a number from x, but you're doing nothing with the result. If you're trying to update x with the result, you need to do just like you're doing with y, and put x = in front of the expression.

    So if you want x to go down by 25, you should write:

    x = x - 25; 
    

    Alternatively, you can write the shorthand:

    x -= 25;     // Note the equal sign 
    

提交回复
热议问题