My code works offline but not working online

#include
#include
#include <math.h>

using namespace std;

int main () {
int n;
long long a;
double sum = 0;
cin >> n;
while(n–){
cin >> a;
string temp = to_string(a);
int counter = 0;
while(counter < temp.length()){
if(temp.at(counter) == ‘1’){
sum = sum + pow(2,counter);
}
counter++;
}
cout << sum << endl;
sum = 0;
}
}

hi nalin
your code is not working for the following test case
7
101
1111
00110
111000
111111
expected output:
5
15
6
56
63
1
255
your output:
5
15
3
7
63
1
255

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.