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 trialfiyinfoluwa fajemirokun
419 PointsAdd 10 to height and store result back into height.
Add 10 to height and store result back into height.
string heightInput = "168";
int height = int.Parse(height);
int height = 10 + ("height");
1 Answer
gyorgyandorka
13,811 PointsHi!
You should pass the
heightInput
variable to theint.Parse()
method, and notheight
, which is a non-existing reference at this point. This will convertheightInput
(astring
type) to anint
, and that integer value can then be assigned to theheight
variable, which has been declared as anint
type reference.On the third line, you should add 10 to the variable
height
and reassign this incremented value to itself (height = height + 10;
). Note that you don't need to redeclare theheight
variable, i.e. you should not give the type (int
) before the variable name again - at this point the program already knows whatheight
refers to. (When you define the type before a variable name, likeint height = ...
it means redeclaration, i.e. creating a completely new reference variable, a "fresh start" forheight
if you like)