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 trialMagnus Stricker
539 PointsSTUCK AGAIN :(
How do I proceed? not sure how to store to the variable height... and not even sure im entering the correct code
2 Answers
jared eiseman
29,023 PointsLet's break it apart: Convert the string in heightInput to an integer using int.Parse. Store the result in a variable named height.
So, we will want to store the result as an integer because that is what we are parsing it to, and it will be named 'height'. We already have a value stored as heightInput that we will be parsing, Finally, we're going to use the method "int.Parse()" to accomplish this. So we're looking to do this:
int height = int.Parse(heightInput);
Magnus Stricker
539 PointsThanks that totally helps :)
The next question asks me to add 10 to height and then store back in the variable height, would I be adding 10 to 168 or just to height?
jared eiseman
29,023 PointsThere's actually a couple ways of doing this. First, the longer way: height = height + 10; I tend to like writing out my operations the long way, out of personal preference because it's more literal and readable to me. The shorthand way would be: height += 10; Either way works fine, and most people prefer the shorthand because it's faster to type. All personal preference I suppose though.
Magnus Stricker
539 PointsMagnus Stricker
539 PointsThanks for your help but I dont understand if heightInput has a value of 168 why we can't just write:
int height = int.Parse("168");
jared eiseman
29,023 Pointsjared eiseman
29,023 PointsYou totally can. The code challenge will fail though because it's asking explicitly to parse the heightInput variable.
To build on that a little. In a scenario in which your gathering input from a user to then parse, you couldn't be collecting it directly into the parse method, you would first be storing it in a variable, and then parsing that variable.
ali raafat
444 Pointsali raafat
444 Pointsits not working "int height = int.Parse(heightInput); " it wil give me an error in the compiler errors.