I have written a code in c++ to count zeros. The input have to take as string. The input will be a digit with 1 and 0.
Example:
Input: 1000000001
Output: 8
The answer should be 8 but my code is showing 0. Where is the problem in the code.
Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
string players;
cin >> players;
int count = 0;
for (int j = 0; j < players.length(); j++)
{
if (players[j] == 0)
{
count++;
}
}
cout << count;
return 0;
}
Please help me to find and solve it. Thank you.