10 to the power of 0

Hello All,

I have this statement in my code:

for (counter = 0; counter <= 2; counter++)
{
runner = (temp_value % 10);
temp_value = temp_value / 10;
return_value = return_value + (runner * (10 ^ counter));
}

When I run this (10 ^ counter), counter = 0, so I am expecting an asnwer of 1, but the returned value is 10.

What am I missing? If anyone know, please guide me.

Regards
Rob
Operator ^ is not "power", but "bitwise XOR".

1
2
3
#include <cmath>

return_value = return_value + (runner * std::pow(10, counter));


http://www.cplusplus.com/reference/clibrary/cmath/pow/
I like to make a small function of my own for these positive integer power operations. (VS2010 doesn't have a int pow(int, int) function in <cmath>:

1
2
3
4
5
6
7
int pow (int base, int exp)
{
    int output = 1;
    while (exp--)
        output *= base;
    return output;
}
Last edited on
Topic archived. No new replies allowed.