static_cast<int>(pow(x, counter+1) % 10) may be enough.
It is not. Inner statement is pow(x, counter+1) % 10 and % operator cannot be applied to floating point value returned by pow. So OP had it right: converting result of pow() to int, then calculating modulus.