Please help me with the task: Count zeros

Hello, I’m working on this task:

Write a method, named AnalyzeString, that returns bool and takes two parameters, string input and out int numberOfZeros. It should calculate the number of zeros in the string and assign it to numberOfZeros. If the string passed to the method is empty, it should return false, otherwise, true. From the Main method, read the input string from the console, and call AnalyzeString with it. If AnalyzeString returns true, print the number of zeros, if it returns false, print ‘The string is invalid.’
Example 1:
>He0llo W0000rld!
5
Example 2:
>
The string is invalid.

Here is my code:


namespace ParametersToMethods
{
   class HowManyZer0s
   {
       static void Main()
       {
           var input = Console.ReadLine();
           int numberOfZeros;

           
           if (AnalyzeString(input, out numberOfZeros))
           {
               Console.WriteLine($"{numberOfZeros}");
           }

           else
           {
               Console.WriteLine("The string is invalid.");
           }
       }

       static bool AnalyzeString(string myString, out int counterOfZeros)
       {
           counterOfZeros = 0;

           if (!string.IsNullOrEmpty(myString))
           {               
               

               for (int i = 0; i < myString.Length; i++)
               {
                    
                   if (myString[i] == '0')
                   {
                       counterOfZeros = counterOfZeros + 1;
                   }
               }

               return true;
           }

           else
           {
               return false;
           }
       }
   }
}

At first glance the code works properly with different scenarios and counts the number of zeros correctly, but when I try to submit it, I see an error “Method ‘AnalyzeString’ does not exist, has the wrong return type, access modifiers, or arguments.”

Could anyone please help me to find my mistake? Thank you in advance

Could it be that in the task they ask you to call parameters
string input and out int numberOfZeros
and you call them:
string myString, out int counterOfZeros
Even though this is not that important from the logical point of view, but I think this is how Codeasy checks your method.

1 Like

Yay! Now it works!!! Thanks a lot :partying_face:

1 Like