Compute sum of even powers of x I am to compute recurrently (not necessarily recursively) the y, where
$$y = {x}^{2n} + {x}^{2(n-1)} + ... + {x}^{4} + {x}^{2} + x$$

Here is what I am doing:

#include &lt;iostream&gt;
using namespace std;

double polynom(unsigned, double);

int main(void)
{
    cout &lt;&lt; polynom(2, 3) &lt;&lt; endl;
    return 0;
}

double polynom(unsigned n, double x)
{
    double currentAdd(x);
    double res(0);
    while (n)
    {
        res += currentAdd;
        currentAdd *= currentAdd;
        --n;
    }
    return res;
}


Is it possible to do it better?
Don't do this:

using namespace std;


See: Why is “using namespace std” considered bad practice?

Its a bad habits you should not get into doing (even for small programs). Bad habits bite you in the butt when you get to larger projects and forget to stop doing them.

Comments

There are a couple of things I would do differently. But I can't say you are doing them wrong.

I prefer not to use unsigned for numeric values.

double polynom(unsigned, double);


There is no way to check that what was passed was not negative. I can easily call this with:

polynom(-1, 2); // Compiler is happy to convert that -1 to a very large 
                // positive number without an y errors. On the reciving
                // side you can not tell if it was an error.


There are very few times when you need the extra bit for larger positive numbers. Any time I have come across this type of case I have just used a larger integer type (not swapped to the unsigned version).

Unsigned values should be reserved for bit masks in user code.

Don't use return in main.

int main(void)
{
    return 0;
}


If you don't put a return at the end of main() then the compiler will automatically plant code to return 0. So it is not technically needed.

Additionally not using the return 0 is a way to indicate that your application can never fail. Note: return 0 indicates a success to the OS and the compiler is planting it by default to indicate successful termination.

So when I see a return 0 at the end of main() I also start to scan the rest of main() to see if there are any other returns (with non zero value) that will indicate the error conditions of the application.

Initialization

This is fine.

    double currentAdd(x);
    double res(0);


But personally I think the = sign provides more context.

    double currentAdd = x;
    double res        = 0;


Prefer for() over while()

This is so 50/50. Its just that for() loops can be slightly more compact.

    while (n)
    {
        --n;
    }
    // over
    for(;n; --n)
    {
    }


Would not worry too much about it though.