Total number of zeros - system does not accept the solution

Even though the output on console is correct, the system does not accept the solution. Here is the code:

/*********************************/
using System;

namespace ParametersToMethods

{

class HowManyZer0sInT0tal

{

    static void Main()

    {

        var count = int.Parse(Console.ReadLine());

        int numberOfZeros = 0;

        int sumNumberOfZeros = 0;

        string inputString;

        int voidString = 0;

       

        for(int i=0; i<count; i++){

            inputString = Console.ReadLine();

            if(!AnalyzeString(inputString, out numberOfZeros)){

            voidString++;

            }

            if(voidString == count){

                Console.WriteLine("All strings are invalid.");

            }

            if(AnalyzeString(inputString, out numberOfZeros)){

               sumNumberOfZeros = sumNumberOfZeros + numberOfZeros;

            }

        }

        Console.WriteLine(sumNumberOfZeros);

    }

    static bool AnalyzeString(string input, out int zeros){

    zeros = 0;

        if(String.IsNullOrEmpty(input)){

            return false;

        }

        for(int i=0; i<input.Length; i++){

            if(input[i] == '0'){

                zeros++;

            }

        }

    return true;

    }

}

}

/*********************************/

I cannot find the error, do you see it anywhere?

thanks a lot

Please specify which task you were solving

Hello;

It is from Beginner class, chapter 5. Task name is Count zeros. If there is a more elegant way to specify these details please do not hesitate to show it to me.

thanks a lot for your patience

Ok, I’ve checked the task and it looks like you are solving the next one - ‘Count total number of zeros’ rather than ‘Count zeros’. Please correct me if I’m wrong.
Unfortunately, right now we don’t have a way to reference a concrete task, that’s why we ask you to copy the whole task description in your question topic on the forum, which makes it easier to spot the problem.
Your code is almost there, what you are missing is the correct method parameters. In the task description it is stated: It should take two parameters, string input, and ref int numberOfZeros, so just rename the parameter in your method and make it ref instead of out. This should be enough, the rest is fine!

Hello;

I checked with both of the tasks and corrected accordingly.

Thanks a lot

1 Like