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

error CS0019: Operator `+' cannot be applied to operands of type `int'

I always get compiler error that i cannot sum int or double ... i tried both and check in internet too but I cannot find the reason for that.

Steven Parker
Steven Parker
229,786 Points

I'll bet there's something else causing the issue. Please show your complete code here for analysis, or provide a link to a workspace snapshot.

OK sorry I thought the code was attached. I agree that there must be something else :) but I don't get WHAT is causing it. Here you can see my solution ... namespace Treehouse.CodeChallenges { class FrogStats { public static double GetAverageTongueLength(Frog[] frogs) { int SumLength = 0;

        for (int i =0; i < frogs.Length; i++)
        {
            SumLength += frogs[i];            
        }
        return SumLength / frogs.Length;
    }
}

}

1 Answer

Steven Parker
Steven Parker
229,786 Points

Oh I see now, you can't add a "frog" to an int. You probably meant to add the frog's tongue length:

            SumLength += frogs[i].TongueLength;

Thanks Steven, that was a stupid mistake which gave me headache.

Steven Parker
Steven Parker
229,786 Points

Erich Freimann — Mistakes are just "learning opportunities". :wink:

Glad I could help. You can mark the question solved by choosing a "best answer".

And happy coding!