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 trialziruibranton
1,649 Pointsloop syntax error?
int mathTotal; bool isComplete;
for (int i = 5; i < 25; i++){ mathTotal += i; }
isComplete = YES;
it keeps telling me better check for syntax error, but it looks right to me... what did i do wrong? thanks.
int mathTotal;
bool isComplete;
for (int i = 5; i < 25; i++){
mathTotal += i;
}
isComplete = YES;
1 Answer
Steve Hunter
57,712 PointsHi there,
You need to reach 25 so use less than or equal to:
int mathTotal;
bool isComplete;
for (int i = 5; i <= 25; i++){
mathTotal += i;
}
isComplete = true;
And I don't know if YES is OK, or if you need to use true. The above code worked.
I hope that helps,
Steve.
ziruibranton
1,649 Pointsziruibranton
1,649 PointsI tried it in the quiz but didn't work i guess i'll try again, thanks Steve!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsJust checked;
YES
works fine is it is just the bounds test ofi
that's wrong. If you just use less than,i
will never reach 25 which is what the challenge asks for. So the loop terminator needs to be less than or equal to 25 so that the value 25 is included in the end result ofmathTotal
.Steve.
ziruibranton
1,649 Pointsziruibranton
1,649 PointsHi Steve, yes that's right it worked! thanks so much!! I was trying to do more lessons on object oriented programming but the site said the page doesn't exist...
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsGlad you got that working.
Let me know if the page still doesn't load. That seems odd.
Steve.
ziruibranton
1,649 Pointsziruibranton
1,649 PointsI asked treehouse, they said they will release the new lessons sometime next week :)