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 trialAndre Robinson
Courses Plus Student 6,057 Pointswhat am i down wrong
what am i down wrong
int mathTotal = 5;
bool isComplete = true ;
for( int mathTotal <= 25; mathTotal++) {
}
2 Answers
Jennifer Nordell
Treehouse TeacherFirst, it's not necessary to initialize your variables. You just need to declare them. Secondly, your for loop is set up incorrectly. You never tell it the starting point and you will want another variable here. Third, you never set isComplete to true after the loop has run. In fact, it's already marked as completed before you run it because you initialized it that way. Take a look at my solution:
int mathTotal;
bool isComplete;
for(int i = 5; i <= 25; i++) {
mathTotal += i;
}
isComplete = true;
Steven Deutsch
21,046 PointsHey Andre Robinson,
Let me see if I can clear a few thing sup for you. First, your mathTotal and isComplete variables don't need default values. Second, lets take a look at the logic of the loop. Your loop needs 3 things to be set up properly:
1) An Index 2) A condition 3) An incrementor
The index will be of type Int, we'll call it i and assign it a starting value of 5.
The condition will dictate when the loop evaluates the code inside its body. We want this loop to execute while i is less than or equal to 25.
The incrementor will be i++ which is just shorthand for i + 1. This means everytime the loop finishes an iteration, the value of i will increase by 1. The loop will then run again and continue to do so until the condition evaluates as false.
Finally, after this loop finishes we will set the value of isComplete to true by assigning it the value.
int mathTotal;
bool isComplete;
for (int i = 5; i <= 25; i++) {
mathTotal += i;
}
isComplete = true;
Good Luck
Andre Robinson
Courses Plus Student 6,057 PointsThank you so much i see now
Andre Robinson
Courses Plus Student 6,057 PointsAndre Robinson
Courses Plus Student 6,057 PointsThank you I saw where i went wrong