Difference between revisions of "CountPlants - AS 2017"
(Created page with "==The Code== <syntaxhighlight lang=Csharp> </syntaxhighlight> ==Explanation==") |
|||
Line 2: | Line 2: | ||
<syntaxhighlight lang=Csharp> | <syntaxhighlight lang=Csharp> | ||
− | + | 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"); | ||
+ | } | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Explanation== | ==Explanation== |
Latest revision as of 09:29, 3 March 2017
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");
}
}