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
Jack Crane
2,745 PointsCode Challenge: Arrays - Confused!
Declare an array of type 'char' called "letters" with a size of 2. Assign the variable "alpha" as the first element of the array "letters".
This is what I did
char letters[] = {alpha, };
Keeps saying "Make sure you're creating a 'char' array and giving it the correct size. As a reminder, arrays are 'zero-based' and start with 0."
I also tried
char letters[2];
letters[0] = alpha;
But no success, any ideas? :/ (thanks in advance)
Jack
5 Answers
Stone Preston
42,016 PointsDeclare an array of type 'char' called "letters" with a size of 2
char letters[2];
Assign the variable "alpha" as the first element of the array "letters".
letters[0] = alpha;
Josh Benard
3,919 PointsDid you make sure to keep the code from the first part of the challenge in the code section? Otherwise it will not know what "alpha" is.
Stone Preston
42,016 PointsI think it would have said that the previous task was no longer passing if that was the case correct?
Josh Benard
3,919 PointsJust tested it.
It actually does not warn the user that they deleted the previous code, it returns the exact error Jack mentioned
Jack Crane
2,745 PointsYe i kept the code, this is what I have now but it says its wrong
'''char letters[2]; letters[0] = alpha;
char bravo; bravo = 'b'; '''
Jack Crane
2,745 PointsSo am I right or whats up?
Josh Benard
3,919 PointsYour code for part 2 should look: char alpha = 'a'; char bravo = 'b';
char letters[2];
letters[0] = alpha;
Stone Preston
42,016 Pointsyou should have
char alpha = 'a';
char bravo = 'b';
char letters[2];
letters[0] = alpha;
letters[1] = bravo;
Jack Crane
2,745 PointsThank you very much for the help both of you :)
Lorace Rimando
1,963 PointsThis helped me a lot too. Initially, I deleted the declarations from the previous question. After struggling a bit I found your posts and all is good. Thanks!
Jack Crane
2,745 PointsJack Crane
2,745 Pointshttp://teamtreehouse.com/library/arrays-4
Stone Preston
42,016 PointsStone Preston
42,016 Pointsedited my answer. Looks like what you had should have worked. are you sure you had