Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Objects Loops and Final Touches For Loops

Help. I'm lost with this array thing can someone help me asap please what do I do here

I cant figure out how to return the average of the array and even when I copy past and switch in my own variables and stuff still I get the error where I can set the array result equal to anything or add it to anything it says that the array dosent return anything

FrogStats.cs
namespace Treehouse.CodeChallenges
{
    class FrogStats
    {
        Frog[] frogs =
        public static double GetAverageTongueLength(Frog[] frogs)
        {
            for(int i = 0; i < frogs.Length; i++)
            {
            }
        }
    }
}
Frog.cs
namespace Treehouse.CodeChallenges
{
    public class Frog
    {
        public int TongueLength { get; }

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,268 Points

Well, you have a good start with the loop. Before the loop starts you might want to declare a variable to hold the total lengths, and initialze it with 0.

Then, inside the loop you could add the TongueLength property of one of the frogs (selected using an index) to the total.

Then, after the loop is done, you can return the total divided by the number of frogs to get the average.

You also won't need that incomplete assignment before the method.