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 trialVictor Ngo
8,324 Points[False Alarm] Possible Error on Challenge 3 of 4
I think there's an error on this challenge. It asks to assign a number to the first index of an array. I did what it told me to but still had a red flag.
6 Answers
Patrick Donahue
9,523 PointsThat is weird.
So I did the challenge over and I got the same error. So to get passed it I changed float math_constants[1] to math_constants[3] and it worked. Not sure what the error really is.
Patrick Donahue
9,523 PointsCan you post your code please?
Victor Ngo
8,324 PointsChallenge task 3 of 4
Assign the number 1.41421 to index 1 of math_constants.
My Code: float math_constants[1]; math_constants[0] = 2.71828; math_constants[1] = 1.41421;
And the response I got was: Bummer! As a reminder, arrays are 'zero-based'. Assigning a number to an array would look something like: name_of_array[0] = 1;
Victor Ngo
8,324 PointsChanging float math_constants[1] to math_constants[2] worked as well. Woohoo! Got the badge! Thanks for the post :D
Patrick Donahue
9,523 PointsSo I looked it up - in C the number in brackets is the amount of array places. Since we had [1] - that means there is only math_constants[0].
Example: char arr[4];// for accommodating 3 characters and one null '\0' byte.
Victor Ngo
8,324 PointsOh, I thought when you initialize an array, that the number in brackets started counting elements from the zeroth element. Thanks for clearing that up!
Patrick Donahue
9,523 PointsNo problem! I needed a refresher on C arrays!