Max power in beginner

max power in beginner that’s my solution for max 2 question when i passed any no of 0 in value n that give me 0 my ans is correct but i don’t why it give me 0 because i used the login when n will find the continue 0 in that then increase the counter variable.when it find 1 than it will break from the loop.can any one help me???

#include
using namespace std;

int main() {
// your code goes here
int n,count=0;
cin>>n;
string x;
cin>>x;
for(int i=n-1;i>=0;i–)
{
if(x[i]==‘0’)
count++;
else
break;
}
cout<<count<<endl;
return 0;
}

for(int i=n-1;i>=0;i--)

Just change this line, you had put single “-”

That’s just the forum screwing the code up, they need to format it

2 Likes

You should format your code.
According to your solution for this Tc
4
0000
answer should be 4.
But in the question it is given that x>=1. So, there will never be any string only of 0.