Code For Detecting power of 2 not working

Taking a CS class, but struggling with bools (other functions I can handle)
This is supposed to detect if a number is the power of two, I played around with it a lot but no matter what its not working ( I think I had it almost there but then I changed it) now it looks like this


void GetValues(int &);
bool mathstate(int);


int main()
{
int n;


cout << "This program determines if a number, input by you, is a power of 2" << endl;
cout << "You will be prompted for a number" << endl;

GetValues(n);


bool result = mathstate(n);

if (result == true)
{
cout << n << " is power of 2" << endl;
}

if (result == false)
{
cout << n << " is not power of 2" << endl;
}

return 0;

}

void GetValues(int & n)
{
cout << "Enter an interger" << endl;
cin >> n;
}

bool mathstate(int n)
{

int k = 1;
bool a;

for (int math = pow(2, k); math < n || a==true;k++)
{


if (n % math == math)
{

a=true;

}


k++;
}

if (a= true) return a;
else

{
a = false;
return a;
}

Topic archived. No new replies allowed.