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 trialDeniz Tuna
6,686 PointsNeed Help with for Loop assignment
i can't seem to get the for loop right. can anyone give me a hand?
int mathTotal;
bool isComplete;
for (int i = 5; i < 26; i++){
mathTotal = mathTotal + i;
mathTotal = 25, isComplete = true;
}
2 Answers
Travis DuPree
Courses Plus Student 3,139 PointsisComplete = mathTotal >= 25 ? true:false;
That is what I used -- I don't think you need the parenthesis and it may reject the answer because it asks to assign true to isComplete and not Yes.
Travis DuPree
Courses Plus Student 3,139 PointsHey Deniz,
It took me a minute to get this one too! It takes a ternary operator because you are evaluating the condition of isComplete as true or false. Your 3 operands being isComplete, the true result, and false result. The full explanation is in Video 3 under More Operators beginning at 2:52.
Deniz Tuna
6,686 PointsHey Travis,
i went back and watched the video adding
isComplete = (mathTotal = 25) ? YES:NO
but i can't seem to get the answer right.
Travis DuPree
Courses Plus Student 3,139 PointsTravis DuPree
Courses Plus Student 3,139 Pointsand don't forget the semicolon
Deniz Tuna
6,686 PointsDeniz Tuna
6,686 PointsHey Travis,
Thank you for your help!! it worked!