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 trialIbrahim Buggati
266 PointsNeeded help with this question. (CodeChallange)
Someone, please help me with this! the question says: Convert the string in heightInput to an integer using int.Parse. Store the result in a variable named height. I tried everything and I could not get it to work..
string heightInput = "168";
string height = heightInput;
int.Parse(heightInput);
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Ibrahim! There are a couple of things going on here. First, we're trying to turn that string into an integer and then store the integer version of it in the variable height
, but you've declared height
to be of type string
. Secondly, you do use the int.Parse
method, but the result of that is neither displayed nor saved anywhere. It's just sort of floating out there in limbo.
Steps to take:
- Declare
height
to be type int - Set
height
to be equal to the result of runningint.Parse
onheightInput
I think you can get it with these hints, but let me know if you're still stuck!
Ibrahim Buggati
266 PointsIbrahim Buggati
266 PointsI'm sorry but I still don't understand..
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherOk, for Step 1 you only need one additional line of code:
int height = int.Parse(heightInput);
This line declares a variable named
height
. We then use the equals sign to indicate an assignment. On the right side of the equals is what is assigned to the variable. In this case, we're taking the string that was stored inheightInput
, converting it to an integer, and assigning the result toheight
. At the end, the value in height will be 168 as opposed to "168". This means that later we can perform mathematical operations on that value.Hope this clears things up!
Ibrahim Buggati
266 PointsIbrahim Buggati
266 PointsOh! i figured it out, i had to think better... thanks for the help! appreciate it