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# Collections GetPowersOf2() error

So in order to solve this exercise i looked up the definition of the Math.Pow method and found this:

public static double Pow (double x, double y); Parameters x Double A double-precision floating-point number to be raised to a power.

y Double A double-precision floating-point number that specifies a power.

Returns Double The number x raised to the power y.

But when i use it as described Math.Pow(i, 2) I get an error messagebut when I switched it around to Math.Pow(2,i) it said all was fine and the exercise was marked as completed. So is there an error in the exercise? Or in the microsoft documentation?

Ok, I re-read it about 5 times now. So what they wanted was to raise 2 to the power of 0,1,.., value. Guess the method name GetPowersOf2 was misleading to me..

2 Answers

Steven Parker
Steven Parker
231,269 Points

One way raises "i" to the power of 2 (a square), and other raises 2 to the power of "i". The name "GetPowersOf2" would imply that they want you to do the latter.

A function that would use the first one would probably have a name like "GetSquares".

Please post a link to the course page if you'd like a more specific answer.

Steven Parker
Steven Parker
231,269 Points

Update: This is probably a good real-world practice. Sometimes deciphering the instructions can be the hardest part of a task! :wink:

"Create a static method named GetPowersOf2 that returns a list of integers of type List<int> containing the powers of 2 from 0 to the value passed in"

I guess "containing 2 raised to the powers from 0 to the value passed in" would have confused me less :)

https://teamtreehouse.com/library/c-collections/lists/lists-2