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 trialHermes Crespo
980 PointsThis challenge does not make sense to me....
...because the I believe I did everything correctly but I am getting the error message: FrogStats.cs(13,30): error CS0019: Operator +' cannot be applied to operands of type
Treehouse.CodeChallenges.Frog' and `double'"... Well sure, that is because the type "Frog[] does not even exist! Arrays must be either of type: int, double, float or string not "Frog". How am I suppose to then use "+", "/" or any other normal math operator to get an average???
namespace Treehouse.CodeChallenges
{
class FrogStats
{
public static double GetAverageTongueLength(Frog[] frogs)
{
double total = 0;
double AverageTongueLength = 0;
for(int index = 0; index < frogs.Length; index++)
{
total = frogs[index] + total;
}
return AverageTongueLength = total / frogs.Length;
}
}
}
namespace Treehouse.CodeChallenges
{
public class Frog
{
public int TongueLength { get; }
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
}
}
1 Answer
Stephen Wall
Courses Plus Student 27,294 PointsYou seem to be getting that error in your for loop:
total = frogs[index] + total;
frogs[index] will return a Frog object, total is an int. So you are trying to add an int to a Frog which wonβt work :)
You need to get the tounge length from each Frog in the frogs array. Try using some dot notation on: frogs[index].