What is wrong in my code

#include
using namespace std;

int steps(int n)
{

int p;
int ans=0;
while(ans<=n)
{	p=ans;
	//cout<<p<<" ";
	ans=1<<i;
	i++;
}
return p;

}
int main()
{
int test;
cin>>test;
while(test–)
{
int n;
cin>>n;
int k=steps(n);
cout<<(n-k+1)<<endl;
}
}

Hello @Nidhi_Alipuria,

Can you please explain your approach?

What are you required to do in this question?
Just find the number of set bits in the inputted number.