CountPlants - AS 2017

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

The Code

static void CountPlants(char[,] Field)
{
    int NumberOfPlants = 0;
    for (int Row = 0; Row < FIELDLENGTH; Row++)
    {
        for (int Column = 0; Column < FIELDWIDTH; Column++)
        {
            if (Field[Row, Column] == PLANT)
            {
                NumberOfPlants++;
            }
        }
    }
    if (NumberOfPlants == 1)
    {
        Console.WriteLine("There is 1 plant growing");
    }
    else
    {
        Console.WriteLine("There are " + NumberOfPlants + " plants growing");
    }
}

Explanation