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 trialStefan Mach
3,691 PointsWhat is wrong with this code?
This says there are compiler errors but I do not see any and the preview is no help at all. What am I missing?
bool isMediumSize;
int inchesTall = 45;
int inchesTall = 64;
if (inchesTall >48 && <68)
{
isMediumSize = TRUE;
}
3 Answers
Steve Hunter
57,712 PointsHi Stefan,
The first part of this challenge asks for a bool
and an int
variable to be created, with the int
being assigned a value of 45. That looks like:
bool isMediumSize;
int inchesTall = 45;
You've done that! Good work.
Next, you change the value assigned to inchesTall
. To do that, you don't need the int
keyword again as the app nows that inchesTall
is an int
.
Then you need an if
conditional. You've identified that correctly and have mainly done the test correctly. You need to check each condition against inchesTall
; you can't do both tests with one mention of inchesTall
, you need to make both tests expressly.
Like this:
bool isMediumSize;
int inchesTall = 45;
inchesTall = 64;
if(inchesTall > 48 && inchesTall < 68){
isMediumSize = TRUE;
}
You had that done!
Steve.
andren
28,558 PointsWhen you specify multiple conditions using &&
you can't just provide a list of conditions based on the fist one, each of the conditions has to be an independent condition that make sense on it's own. Meaning that you have to compare to the inchesTall
variable in both conditions.
The second issue is that you declare the inchesTall
variable twice, which is invalid. When you are changing the value of a variable you should not include the type of the variable, that is only done when you want to create a new variable.
If you fix those issues like this:
bool isMediumSize;
int inchesTall = 45;
inchesTall = 64;
if (inchesTall >48 && inchesTall <68)
{
isMediumSize = TRUE;
}
Then the code will pass.
Stefan Mach
3,691 PointsThank you too.
Stefan Mach
3,691 PointsStefan Mach
3,691 PointsThanks
Steve Hunter
57,712 PointsSteve Hunter
57,712 Points